diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-02-26 21:47:45 +0200 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-02-26 22:45:17 +0200 |
commit | 573ebab3adc0c63b84e2caf33c80ee13fde08004 (patch) | |
tree | 16a5a5e711eb5de4c4410142d3459186c74b3627 | |
parent | 6abeefff8d74a003d8751549fbfda430194d9f3d (diff) | |
download | aconf-0.3.0.tar.bz2 aconf-0.3.0.tar.xz |
model: disable deletion from non-editable collectionsv0.3.0
-rw-r--r-- | acf2/model/model.lua | 2 | ||||
-rw-r--r-- | acf2/model/node.lua | 10 |
2 files changed, 8 insertions, 4 deletions
diff --git a/acf2/model/model.lua b/acf2/model/model.lua index 55fe95f..cf90d88 100644 --- a/acf2/model/model.lua +++ b/acf2/model/model.lua @@ -108,7 +108,7 @@ end M.Model = M.new(node.TreeNode) function M.Model:init(context) - super(self, M.Model):init(context, 'model') + super(self, M.Model):init(context, 'model', true) local mt = getmetatable(self) diff --git a/acf2/model/node.lua b/acf2/model/node.lua index 711680e..86a9f0c 100644 --- a/acf2/model/node.lua +++ b/acf2/model/node.lua @@ -58,7 +58,7 @@ local function equal_tns(tn1, tn2) return getmetatable(tn1).path == getmetatable(tn2).path end -function M.TreeNode:init(context, dtype) +function M.TreeNode:init(context, dtype, editable) local mt = getmetatable(self) update(mt, context) @@ -84,7 +84,9 @@ function M.TreeNode:init(context, dtype) function mt.member_removable(k) local v = mt.load(k, {dereference=false}) - return not isinstance(v, M.TreeNode) or getmetatable(v).removable() + return editable and ( + not isinstance(v, M.TreeNode) or getmetatable(v).removable() + ) end function mt.check_removable(k, v) @@ -194,7 +196,9 @@ end M.Collection = class(M.TreeNode) function M.Collection:init(context, params, dtype) - super(self, M.Collection):init(context, dtype or 'collection') + super(self, M.Collection):init( + context, dtype or 'collection', params.editable + ) self.init = nil self.fetch = nil |