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:
Nathan Schneider
2022-02-09 22:14:26 -07:00
parent f950b5b94c
commit 2028f1ee85
7 changed files with 76 additions and 52 deletions

View File

@ -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,