bugfix orgs
This commit is contained in:
parent
ccbe3d2afb
commit
252c04c6c7
@ -77,7 +77,7 @@ dofile (topdir .. "/api.lua")
|
|||||||
-- Final checks
|
-- Final checks
|
||||||
|
|
||||||
-- create instance if not present
|
-- 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())
|
modpol.add_org("instance", modpol.list_users())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
-- preserve records -- if true, will store org ledgers when they are closed, for later reference.
|
-- preserve records -- if true, will store org ledgers when they are closed, for later reference.
|
||||||
local preserve_records = true
|
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 {}
|
modpol.default_org_policies = modpol.default_org_policies or {}
|
||||||
|
|
||||||
|
|
||||||
@ -45,29 +45,38 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--define the template of a ledger entry
|
--define the template of a ledger entry
|
||||||
modpol.ledger_entry_temp = {
|
modpol.ledger_entry_temp = function()
|
||||||
timestamp = '',
|
|
||||||
entrytype = nil,
|
return {
|
||||||
action_msg = '',
|
timestamp = '',
|
||||||
org_name = nil,
|
entrytype = nil,
|
||||||
org_id = nil,
|
action_msg = '',
|
||||||
}
|
org_name = nil,
|
||||||
|
org_id = nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- define the basic template of an org.
|
-- define the basic template of an org.
|
||||||
|
|
||||||
modpol.org_temp = {
|
|
||||||
id = nil,
|
|
||||||
name = nil,
|
|
||||||
policies = {},
|
|
||||||
members = {},
|
|
||||||
ledger = {},
|
|
||||||
parent = nil,
|
|
||||||
children = {},
|
|
||||||
properties = {},
|
|
||||||
old_names = {},
|
|
||||||
|
|
||||||
}
|
modpol.org_temp = function()
|
||||||
|
|
||||||
|
return {
|
||||||
|
id = nil,
|
||||||
|
name = nil,
|
||||||
|
policies = {},
|
||||||
|
members = {},
|
||||||
|
ledger = {},
|
||||||
|
parent = nil,
|
||||||
|
children = {},
|
||||||
|
properties = {},
|
||||||
|
old_names = {},
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
-- Function: modpol.create_ledger_entry
|
-- Function: modpol.create_ledger_entry
|
||||||
@ -78,7 +87,7 @@ modpol.org_temp = {
|
|||||||
-- and returns a valid ledger entry table
|
-- and returns a valid ledger entry table
|
||||||
|
|
||||||
modpol.create_ledger_entry = function(action_msg, org_id, entry_type)
|
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
|
if action_msg and type(action_msg) == 'string' then
|
||||||
entry.action_msg = action_msg
|
entry.action_msg = action_msg
|
||||||
end
|
end
|
||||||
@ -114,13 +123,22 @@ modpol.record = function (org_id, msg, type)
|
|||||||
-- Record in global ledger
|
-- Record in global ledger
|
||||||
table.insert (modpol.ledger, entry)
|
table.insert (modpol.ledger, entry)
|
||||||
-- Record in "org"-specific ledger
|
-- Record in "org"-specific ledger
|
||||||
|
|
||||||
|
|
||||||
if modpol.orgs [org_id] ~= nil then
|
if modpol.orgs [org_id] ~= nil then
|
||||||
local org_ledger = modpol.orgs [org_id]["ledger"]
|
|
||||||
if org_ledger == nil then
|
local org_ledger = modpol.orgs [org_id]["ledger"]
|
||||||
modpol.orgs [org_id]["ledger"] = { entry }
|
|
||||||
else
|
if org_ledger == nil then
|
||||||
modpol.orgs [org_id]["ledger"] = table.insert (org_ledger, entry)
|
|
||||||
end
|
modpol.orgs [org_id]["ledger"] = { entry }
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
table.insert (org_ledger, entry)
|
||||||
|
modpol.orgs [org_id]["ledger"] = org_ledger
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
modpol.store_data() -- Copy data to disk
|
modpol.store_data() -- Copy data to disk
|
||||||
@ -167,60 +185,63 @@ end
|
|||||||
-- with arbitrary properties
|
-- with arbitrary properties
|
||||||
|
|
||||||
modpol.add_org = function(org_name, members, parent_id, properties)
|
modpol.add_org = function(org_name, members, parent_id, properties)
|
||||||
local str
|
|
||||||
|
|
||||||
if modpol.ocutil.str_empty (org_name) then
|
local str
|
||||||
return false,"Error: Org needs a name"
|
|
||||||
end
|
|
||||||
|
|
||||||
if parent_id and not modpol.orgs[parent_id] then
|
if modpol.ocutil.str_empty (org_name) then
|
||||||
return false,"Error: Parent_id must be a valid existing org id"
|
return false,"Error: Org needs a name"
|
||||||
end
|
end
|
||||||
|
|
||||||
if properties and not type(properties) == 'table' then
|
if parent_id and not modpol.orgs[parent_id] then
|
||||||
return false,"Error: Properties must be a table"
|
return false,"Error: Parent_id must be a valid existing org id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
modpol.ocutil.log ("Attempting to add new org " .. org_name)
|
if properties and not type(properties) == 'table' then
|
||||||
|
return false,"Error: Properties must be a table"
|
||||||
if modpol.get_org_id_by_name(org_name) ~= nil then
|
end
|
||||||
str = "Error: Org " .. org_name .. " already exists"
|
|
||||||
modpol.ocutil.log (str)
|
|
||||||
return false,str
|
|
||||||
end
|
|
||||||
|
|
||||||
local org_id = modpol.id_counter
|
modpol.ocutil.log ("Attempting to add new org " .. org_name)
|
||||||
modpol.id_counter = modpol.id_counter + 1
|
|
||||||
|
if modpol.get_org_id_by_name(org_name) ~= nil then
|
||||||
|
str = "Error: Org " .. org_name .. " already exists"
|
||||||
|
modpol.ocutil.log (str)
|
||||||
|
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.
|
-- 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
|
-- otherwise, it will have a parent of instance's id if not otherwise defined
|
||||||
local parent_org_id = nil
|
|
||||||
|
|
||||||
|
|
||||||
if parent_id and not(modpol.get_org_id_by_name('instance') == org_id) then
|
local parent_org_id = nil
|
||||||
|
|
||||||
|
local instance_id = modpol.get_org_id_by_name('instance')
|
||||||
|
|
||||||
|
if parent_id and instance_id and not(instance_id == org_id) then
|
||||||
parent_org_id = parent_id
|
parent_org_id = parent_id
|
||||||
end
|
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')
|
parent_org_id = modpol.get_org_id_by_name ( 'instance' )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local props = properties or {}
|
|
||||||
|
|
||||||
|
|
||||||
-- actually add the org
|
-- actually add the org
|
||||||
local org = modpol.org_temp
|
local org = modpol.org_temp()
|
||||||
local default_policies = modpol.default_org_policies or {}
|
local default_policies = modpol.default_org_policies or {}
|
||||||
org.id = org_id
|
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.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.members = members
|
||||||
org.parent = parent_org_id
|
org.parent = parent_org_id
|
||||||
org.properties = props
|
org.properties = properites or org.properties
|
||||||
org.policies = default_policies
|
org.policies = default_policies
|
||||||
|
org.children = {}
|
||||||
|
|
||||||
modpol.orgs [org_id] = org
|
modpol.orgs [org_id] = org
|
||||||
|
|
||||||
@ -350,6 +371,11 @@ modpol.list_orgs = function()
|
|||||||
return outbuf
|
return outbuf
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
-- Function: modpol.reset_orgs
|
-- Function: modpol.reset_orgs
|
||||||
-- Params: None
|
-- Params: None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user