Merge branch 'Redo_orgs' into 'master'
bugfix orgs See merge request medlabboulder/modpol!12
This commit is contained in:
commit
fc5e117b63
@ -77,7 +77,7 @@ dofile (topdir .. "/api.lua")
|
||||
-- Final checks
|
||||
|
||||
-- create instance if not present
|
||||
if (modpol.orgs["instance"] == nil) then
|
||||
if not modpol.get_org_id_by_name('instance') then
|
||||
modpol.add_org("instance", modpol.list_users())
|
||||
end
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
-- preserve records -- if true, will store org ledgers when they are closed, for later reference.
|
||||
local preserve_records = true
|
||||
|
||||
-- policies assigned to any org can go here
|
||||
-- policies to be assigned to every org can go here
|
||||
modpol.default_org_policies = modpol.default_org_policies or {}
|
||||
|
||||
|
||||
@ -45,7 +45,9 @@ end
|
||||
|
||||
|
||||
--define the template of a ledger entry
|
||||
modpol.ledger_entry_temp = {
|
||||
modpol.ledger_entry_temp = function()
|
||||
|
||||
return {
|
||||
timestamp = '',
|
||||
entrytype = nil,
|
||||
action_msg = '',
|
||||
@ -53,10 +55,15 @@ modpol.ledger_entry_temp = {
|
||||
org_id = nil,
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
|
||||
-- define the basic template of an org.
|
||||
|
||||
modpol.org_temp = {
|
||||
|
||||
modpol.org_temp = function()
|
||||
|
||||
return {
|
||||
id = nil,
|
||||
name = nil,
|
||||
policies = {},
|
||||
@ -69,6 +76,8 @@ modpol.org_temp = {
|
||||
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- Function: modpol.create_ledger_entry
|
||||
-- Params: strings: action_msg, type, number: org_id
|
||||
@ -78,7 +87,7 @@ modpol.org_temp = {
|
||||
-- and returns a valid ledger entry table
|
||||
|
||||
modpol.create_ledger_entry = function(action_msg, org_id, entry_type)
|
||||
local entry = modpol.ledger_entry_temp
|
||||
local entry = modpol.ledger_entry_temp()
|
||||
if action_msg and type(action_msg) == 'string' then
|
||||
entry.action_msg = action_msg
|
||||
end
|
||||
@ -114,12 +123,22 @@ modpol.record = function (org_id, msg, type)
|
||||
-- Record in global ledger
|
||||
table.insert (modpol.ledger, entry)
|
||||
-- Record in "org"-specific ledger
|
||||
|
||||
|
||||
if modpol.orgs [org_id] ~= nil then
|
||||
|
||||
local org_ledger = modpol.orgs [org_id]["ledger"]
|
||||
|
||||
if org_ledger == nil then
|
||||
|
||||
modpol.orgs [org_id]["ledger"] = { entry }
|
||||
print("Warning: Org ".. org_id .. " did not have a ledger. This is an error.")
|
||||
|
||||
else
|
||||
modpol.orgs [org_id]["ledger"] = table.insert (org_ledger, entry)
|
||||
|
||||
table.insert (org_ledger, entry)
|
||||
modpol.orgs [org_id]["ledger"] = org_ledger
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@ -167,6 +186,7 @@ end
|
||||
-- with arbitrary properties
|
||||
|
||||
modpol.add_org = function(org_name, members, parent_id, properties)
|
||||
|
||||
local str
|
||||
|
||||
if modpol.ocutil.str_empty (org_name) then
|
||||
@ -190,37 +210,39 @@ modpol.add_org = function(org_name, members, parent_id, properties)
|
||||
return false,str
|
||||
end
|
||||
|
||||
-- assign a new id to the new org
|
||||
local org_id = modpol.id_counter
|
||||
modpol.id_counter = modpol.id_counter + 1
|
||||
|
||||
|
||||
-- the instance will have a parent of nil if it is the instance.
|
||||
-- otherwise, it will have a parent of instance's id if not otherwise defined
|
||||
|
||||
local parent_org_id = nil
|
||||
|
||||
local instance_id = modpol.get_org_id_by_name('instance')
|
||||
|
||||
if parent_id and not(modpol.get_org_id_by_name('instance') == org_id) then
|
||||
if parent_id and instance_id and not(instance_id == org_id) then
|
||||
parent_org_id = parent_id
|
||||
end
|
||||
|
||||
if not parent_id and not(modpol.get_org_id_by_name('instance') == org_id) then
|
||||
if not parent_id and instance_id and not ( instance_id == org_id ) then
|
||||
parent_org_id = modpol.get_org_id_by_name ( 'instance' )
|
||||
end
|
||||
|
||||
|
||||
|
||||
local props = properties or {}
|
||||
|
||||
|
||||
-- actually add the org
|
||||
local org = modpol.org_temp
|
||||
local org = modpol.org_temp()
|
||||
local default_policies = modpol.default_org_policies or {}
|
||||
org.id = org_id
|
||||
org.name = org_name -- do not change this without the proper api function. This is only a reference, not the only place this is recorded.
|
||||
org.members = members
|
||||
org.parent = parent_org_id
|
||||
org.properties = props
|
||||
org.properties = properites or org.properties
|
||||
org.policies = default_policies
|
||||
org.children = {}
|
||||
|
||||
modpol.orgs [org_id] = org
|
||||
|
||||
@ -350,6 +372,11 @@ modpol.list_orgs = function()
|
||||
return outbuf
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- ===================================================================
|
||||
-- Function: modpol.reset_orgs
|
||||
-- Params: None
|
||||
|
Loading…
x
Reference in New Issue
Block a user