summaryrefslogtreecommitdiffstats
path: root/acf2/model/permission.lua
blob: 9911ba0cea0d5c3cbaf6fdc172c04f6418e821ee (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-2013 Kaarle Ritvanen
See LICENSE file for license details
--]]

local M = {}

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

function M.define(path, ...)
   local txn = start_txn()
   local db = txn:fetch('/auth/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