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

@ -22,8 +22,9 @@ change_policy.config = {
function change_policy:initiate(result)
-- prepare module options
local available_modules = {}
for k,org_mod in pairs(self.org.modules) do
if not org_mod.hide then
for k,org_mod in pairs(modpol.modules) do
if not org_mod.hide and
self.org.policies[k] then
available_modules[org_mod.slug] = modpol.util.copy_table(org_mod)
end end
local modules_list = {}
@ -48,7 +49,7 @@ function change_policy:initiate(result)
self.initiator, "Choose a module to change policies for:",
modules_list,
function(mod_choice)
local this_module = self.org.modules[mod_choice]
local this_module = modpol.modules[mod_choice]
local module_policies = this_module.config
local policy_list = {}
for k,v in pairs(module_policies) do
@ -70,10 +71,9 @@ function change_policy:initiate(result)
function(policy_choice)
modpol.interactions.text_query(
self.initiator,
"Use carefully!\n" ..
"Current " .. policy_choice .. " value: " ..
tostring(self.org.modules[mod_choice][policy_choice])
.. "\nChange value to:",
tostring(modpol.modules[mod_choice][policy_choice])
.. "\nChange value to (be careful!):",
function(policy_input)
self:approve_change(
mod_choice,
@ -99,7 +99,7 @@ function change_policy:approve_change(module_slug, policy, input)
self.initiator,
"Updating " .. policy .. " policy on module " ..
module_slug .. " with: " .. input)
self.org.modules[module_slug].config[policy] = input
self.org.policies[module_slug][policy] = input
modpol.interactions.org_dashboard(
self.initiator, self.org.id)
if self.data.result then self.data.result() end