summaryrefslogtreecommitdiffstats
path: root/aconf
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-03-24 22:48:35 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-03-25 09:03:09 +0200
commit57f9a806dc8fd59912d9549f78698b3b42251068 (patch)
tree885f57a7dbd3a6e2955be8d104a8b013334bc98a /aconf
parent07b911f80409266a7b0f698a8e500b6da6322b56 (diff)
downloadaconf-57f9a806dc8fd59912d9549f78698b3b42251068.tar.bz2
aconf-57f9a806dc8fd59912d9549f78698b3b42251068.tar.xz
model: allow editing non-editable fields in privileged mode
Diffstat (limited to 'aconf')
-rw-r--r--aconf/model/field.lua2
-rw-r--r--aconf/model/node.lua33
2 files changed, 18 insertions, 17 deletions
diff --git a/aconf/model/field.lua b/aconf/model/field.lua
index 59b6700..cf14909 100644
--- a/aconf/model/field.lua
+++ b/aconf/model/field.lua
@@ -212,7 +212,7 @@ function M.Field:normalize(context, value) return value end
function M.Field:validate(context, value) end
function M.Field:save(context, value)
- if not self:_editable(context) then
+ if not (context.privileged or self:_editable(context)) then
raise(context.path, 'Is not editable')
end
diff --git a/aconf/model/node.lua b/aconf/model/node.lua
index 95d9e79..40e4422 100644
--- a/aconf/model/node.lua
+++ b/aconf/model/node.lua
@@ -179,7 +179,7 @@ function M.TreeNode:init(context, params)
end
function mt.check_removable(k)
- if not key_removable(k) then
+ if not (mt.privileged or key_removable(k)) then
raise(pth.join(mt.path, k), 'Cannot be deleted')
end
end
@@ -308,24 +308,25 @@ function M.Collection:init(context, params)
end
function mt.save(k, v)
- local delete = v == nil
- local old = mt.load(k, {dereference=false})
-
- if old == nil then
- if delete then return end
- if not params.editable then
- raise(mt.path, 'Collection is not editable')
- end
- mt.check_permission('create')
-
- elseif delete then mt.check_removable(k)
+ if not mt.privileged then
+ local delete = v == nil
+ local old = mt.load(k, {dereference=false})
+
+ if old == nil then
+ if delete then return end
+ if not params.editable then
+ raise(mt.path, 'Collection is not editable')
+ end
+ mt.check_permission('create')
- elseif type(old) == 'table' then
- mt.check_removable(k)
- mt.check_permission('create')
+ elseif delete then mt.check_removable(k)
- else mt.check_permission('modify') end
+ elseif type(old) == 'table' then
+ mt.check_removable(k)
+ mt.check_permission('create')
+ else mt.check_permission('modify') end
+ end
if params.key then
local kf = M.BoundMember(self, k, params.key)