Refactored policy structure
Previously, all modules in an org were fully copied into that org. Now, the only copy of the modules is at modpol.modules, and orgs have a policy table at [org].policies, which overrides the config table in any given module.
This commit is contained in:
@ -14,7 +14,7 @@ function temp_org()
|
||||
return {
|
||||
id = nil,
|
||||
name = nil,
|
||||
modules = modpol.util.copy_table(modpol.modules),
|
||||
policies = {},
|
||||
processes = {},
|
||||
pending = {},
|
||||
members = {},
|
||||
@ -105,6 +105,9 @@ function modpol.orgs.init_instance()
|
||||
local instance = temp_org()
|
||||
instance.id = 1
|
||||
instance.name = "Root"
|
||||
for i,v in pairs(modpol.modules) do
|
||||
instance.policies[i] = {}
|
||||
end
|
||||
|
||||
setmetatable(instance, modpol.orgs)
|
||||
|
||||
@ -183,7 +186,7 @@ function modpol.orgs:add_org(name, user)
|
||||
child_org.name = name
|
||||
child_org.parent = self.id
|
||||
child_org.processes = {}
|
||||
child_org.modules = modpol.util.copy_table(self.modules)
|
||||
child_org.policies = modpol.util.copy_table(self.policies)
|
||||
|
||||
setmetatable(child_org, modpol.orgs)
|
||||
|
||||
|
@ -15,7 +15,7 @@ function modpol.orgs:call_module(module_slug, initiator, config, result, parent_
|
||||
|
||||
local index = #self.processes + 1
|
||||
|
||||
local module = self.modules[module_slug]
|
||||
local module = modpol.modules[module_slug]
|
||||
|
||||
-- first applies any relevant org policies
|
||||
-- then overrides with the config values given on input
|
||||
@ -23,6 +23,11 @@ function modpol.orgs:call_module(module_slug, initiator, config, result, parent_
|
||||
if modpol.util.num_pairs(module.config) > 0 then
|
||||
for k, v in pairs(module.config) do
|
||||
new_config[k] = v
|
||||
-- overrides with org policies
|
||||
if self.policies[module_slug]
|
||||
and self.policies[module_slug][k] then
|
||||
new_config[k] = self.policies[module_slug][k]
|
||||
end
|
||||
-- overrides with input settings
|
||||
if config and config[k] then
|
||||
new_config[k] = config[k]
|
||||
|
Reference in New Issue
Block a user