More basic functionality for policy change
Created change_policy module (though it still does not have an approval flow; improved display_policies and display_processes modules.
This commit is contained in:
parent
9d4ad377e6
commit
f950b5b94c
@ -15,6 +15,7 @@ dofile (localdir .. "/interactions/interactions.lua")
|
||||
dofile (localdir .. "/modules/add_child_org_consent.lua")
|
||||
dofile (localdir .. "/modules/add_child_org.lua")
|
||||
dofile (localdir .. "/modules/change_modules.lua")
|
||||
dofile (localdir .. "/modules/change_policy.lua")
|
||||
dofile (localdir .. "/modules/consent.lua")
|
||||
dofile (localdir .. "/modules/create_token.lua")
|
||||
dofile (localdir .. "/modules/defer_consent.lua")
|
||||
|
110
modpol_core/modules/change_policy.lua
Normal file
110
modpol_core/modules/change_policy.lua
Normal file
@ -0,0 +1,110 @@
|
||||
--- change_policy
|
||||
-- @module change_policy
|
||||
|
||||
local change_policy = {
|
||||
name = "Change policy",
|
||||
slug = "change_policy",
|
||||
desc = "Change a policy in a module",
|
||||
hide = false;
|
||||
}
|
||||
|
||||
change_policy.data = {
|
||||
result = nil
|
||||
}
|
||||
|
||||
change_policy.config = {
|
||||
approval = "none"
|
||||
}
|
||||
|
||||
--- Change modules initiate
|
||||
-- @function change_policy:initiate
|
||||
-- @param result Callback if this module is embedded in other modules
|
||||
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
|
||||
available_modules[org_mod.slug] = modpol.util.copy_table(org_mod)
|
||||
end end
|
||||
local modules_list = {}
|
||||
local modules_count = 0
|
||||
for k,v in pairs(available_modules) do
|
||||
table.insert(modules_list,v.slug)
|
||||
modules_count = modules_count + 1
|
||||
end
|
||||
-- abort if no modules to remove
|
||||
if modules_count == 0 then
|
||||
modpol.interactions.message(
|
||||
self.initiator, "Org has no modules")
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.id)
|
||||
if self.data.result then self.data.result() end
|
||||
self.org:delete_process(self.id)
|
||||
return
|
||||
end
|
||||
table.sort(modules_list)
|
||||
-- now ask which to remove
|
||||
modpol.interactions.dropdown_query(
|
||||
self.initiator, "Choose a module to change policies for:",
|
||||
modules_list,
|
||||
function(mod_choice)
|
||||
local this_module = self.org.modules[mod_choice]
|
||||
local module_policies = this_module.config
|
||||
local policy_list = {}
|
||||
for k,v in pairs(module_policies) do
|
||||
table.insert(policy_list, k)
|
||||
end
|
||||
if #policy_list == 0 then
|
||||
-- No policies; abort
|
||||
modpol.interactions.message(
|
||||
self.initiator, "Module has no policy options")
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.id)
|
||||
if self.data.result then self.data.result() end
|
||||
self.org:delete_process(self.id)
|
||||
return
|
||||
end
|
||||
modpol.interactions.dropdown_query(
|
||||
self.initiator, "Choose a policy to change:",
|
||||
policy_list,
|
||||
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:",
|
||||
function(policy_input)
|
||||
self:approve_change(
|
||||
mod_choice,
|
||||
policy_choice,
|
||||
policy_input)
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
--- Propose a change.
|
||||
-- Type "add" or "remove"
|
||||
-- @function change_policy:approve_change
|
||||
-- @param module (string) slug of module
|
||||
-- @param policy (string) policy slug
|
||||
-- @param input (string) input content
|
||||
function change_policy:approve_change(module_slug, policy, input)
|
||||
-- NEED TO ADD APPROVAL CODE for consent, etc.
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"Updating " .. policy .. " policy on module " ..
|
||||
module_slug .. " with: " .. input)
|
||||
self.org.modules[module_slug].config[policy] = input
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.id)
|
||||
if self.data.result then self.data.result() end
|
||||
self.org:delete_process(self.id)
|
||||
return
|
||||
end
|
||||
|
||||
modpol.modules.change_policy = change_policy
|
@ -20,28 +20,25 @@ display_policies.config = {
|
||||
function display_policies:initiate(result)
|
||||
local display_table = {}
|
||||
for k,v in pairs(self.org.modules) do
|
||||
if v ~= "deleted" then
|
||||
local input = v.name
|
||||
table.insert(display_table, input)
|
||||
if v.config
|
||||
and modpol.util.num_pairs(v.config) > 0 then
|
||||
table.insert(display_table, "Policies:")
|
||||
for k2,v2 in pairs(v.config) do
|
||||
local v2_string = ""
|
||||
if type(v2) ~= "string"
|
||||
and type(v2) ~= "table" then
|
||||
v2_string = tostring(v2)
|
||||
elseif type(v2) == "table" then
|
||||
v2_string = tostring(v2)
|
||||
else
|
||||
v2_string = "Could not render"
|
||||
end
|
||||
input = k2..": "..v2_string
|
||||
table.insert(display_table, input)
|
||||
local input = v.name
|
||||
table.insert(display_table, input)
|
||||
if v.config
|
||||
and modpol.util.num_pairs(v.config) > 0 then
|
||||
for k2,v2 in pairs(v.config) do
|
||||
local v2_string = ""
|
||||
if type(v2) == "string" then
|
||||
v2_string = v2
|
||||
elseif type(v2) == "table"
|
||||
or type(v2) == "number" then
|
||||
v2_string = tostring(v2)
|
||||
else
|
||||
v2_string = "Could not render"
|
||||
end
|
||||
input = k2..": "..v2_string
|
||||
table.insert(display_table, input)
|
||||
end
|
||||
table.insert(display_table, "\n")
|
||||
end
|
||||
table.insert(display_table, "---")
|
||||
end
|
||||
local output = table.concat(display_table,"\n")
|
||||
if #display_table == 0 then
|
||||
|
@ -31,10 +31,10 @@ function display_processes:initiate(result)
|
||||
table.insert(display_table, "Policies:")
|
||||
for k2,v2 in pairs(v.config) do
|
||||
local v2_string = ""
|
||||
if type(v2) ~= "string"
|
||||
and type(v2) ~= "table" then
|
||||
v2_string = tostring(v2)
|
||||
elseif type(v2) == "table" then
|
||||
if type(v2) == "string" then
|
||||
v2_string = v2
|
||||
elseif type(v2) == "table"
|
||||
or type(v2) == "number" then
|
||||
v2_string = tostring(v2)
|
||||
else
|
||||
v2_string = "Could not render"
|
||||
@ -43,7 +43,7 @@ function display_processes:initiate(result)
|
||||
table.insert(display_table, input)
|
||||
end
|
||||
end
|
||||
table.insert(display_table, "\n")
|
||||
table.insert(display_table, "---")
|
||||
end
|
||||
end
|
||||
local output = table.concat(display_table,"\n")
|
||||
|
Loading…
x
Reference in New Issue
Block a user