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:
@ -18,13 +18,23 @@ function modpol.interactions.get_policy_string(
|
||||
local this_org = modpol.orgs.get_org(org)
|
||||
local this_module = modpol.modules[module_slug]
|
||||
local output = {}
|
||||
if modpol.util.num_pairs(this_module.config) > 0 then
|
||||
for k, v in pairs(this_module.config) do
|
||||
local this_policy = k .. " - " .. tostring(v)
|
||||
table.insert(output,this_policy)
|
||||
end
|
||||
end
|
||||
return "Policies:\n" .. table.concat(output, sep)
|
||||
if not this_org.policies[module_slug] then
|
||||
return "Module not in org"
|
||||
elseif modpol.util.num_pairs(this_module.config) > 0 then
|
||||
for k, v in pairs(this_module.config) do
|
||||
local this_policy = "[Policy error]"
|
||||
if this_org.policies[module_slug][k] then
|
||||
this_policy =
|
||||
tostring(this_org.policies[module_slug][k])
|
||||
else
|
||||
this_policy = tostring(v)
|
||||
end
|
||||
table.insert(output, k.." - "..this_policy)
|
||||
end
|
||||
return "Policies:\n" .. table.concat(output, sep)
|
||||
else
|
||||
return "No policies"
|
||||
end
|
||||
end
|
||||
|
||||
-- DASHBOARDS
|
||||
@ -143,9 +153,10 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
|
||||
-- prepare modules menu
|
||||
local modules = {}
|
||||
if org.modules then
|
||||
for k,v in pairs(org.modules) do
|
||||
if not v.hide then -- hide utility modules
|
||||
if modpol.modules then
|
||||
for k,v in pairs(modpol.modules) do
|
||||
if not v.hide and -- hide utility modules
|
||||
org.policies[k] then -- org includes it
|
||||
local module_entry = v.slug
|
||||
table.insert(modules, module_entry)
|
||||
end
|
||||
@ -186,7 +197,7 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
module_result = true
|
||||
end
|
||||
end
|
||||
local module = org.modules[module_sel]
|
||||
local module = modpol.modules[module_sel]
|
||||
if module_result then
|
||||
modpol.interactions.binary_poll_user(
|
||||
user,
|
||||
|
Reference in New Issue
Block a user