summaryrefslogtreecommitdiffstats
path: root/aconf/model/permission.lua
blob: f7f5be1e60b6f61f70a4eb05c9430961c4aaa93c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
--[[
Copyright (c) 2012-2014 Kaarle Ritvanen
See LICENSE file for license details
--]]

local M = {}

local node = require('aconf.model.node')
local start_txn = require('aconf.transaction')

function M.define(path, ...)
   local txn = start_txn()
   local db = txn:fetch('/aaa/permissions')
   for _, permission in ipairs{...} do node.insert(db, permission..path) end
   txn:commit()
end

function M.defaults(path)
   M.define(path, 'read', 'create', 'modify', 'delete')
   for _, action in ipairs(node.meta(start_txn():fetch(path)).actions or {}) do
      M.define(path, action.name)
   end
end

return M