First shot at a generic approve() function for modules, testing on change_policy
This commit is contained in:
parent
99c75861b0
commit
1f33232394
@ -101,7 +101,7 @@ We are grateful for initial support for this project from a residency with [The
|
||||
|
||||
## Contributing
|
||||
|
||||
We'd love to welcome more contributors. Please join the conversation in the [Issues](https://gitlab.com/medlabboulder/modpol/-/issues), our [Matrix.org channel](https://matrix.to/#/#minetest-modpol:matrix.org), and the [Minetest.net forum](https://forum.minetest.net/viewtopic.php?f=47&t=26037).
|
||||
We'd love to welcome more contributors. Please join the conversation in the [Issues](https://gitlab.com/medlabboulder/modpol/-/issues), the \#modpol channel at the [Metagovernance Project](https://metagov.org) Slack, and the [Minetest.net forum](https://forum.minetest.net/viewtopic.php?f=47&t=26037).
|
||||
|
||||
Learn more about the project and how to develop your own modules in [the wiki](https://gitlab.com/medlabboulder/modpol/-/wikis/home).
|
||||
|
||||
|
@ -9,11 +9,11 @@ local change_policy = {
|
||||
}
|
||||
|
||||
change_policy.data = {
|
||||
result = nil
|
||||
result = false
|
||||
}
|
||||
|
||||
change_policy.config = {
|
||||
approval = "none"
|
||||
approval_module = false
|
||||
}
|
||||
|
||||
--- Change modules initiate
|
||||
@ -23,8 +23,7 @@ function change_policy:initiate(result)
|
||||
-- prepare module options
|
||||
local available_modules = {}
|
||||
for k,org_mod in pairs(modpol.modules) do
|
||||
if not org_mod.hide and
|
||||
self.org.policies[k] then
|
||||
if self.org.policies[k] then
|
||||
available_modules[org_mod.slug] = modpol.util.copy_table(org_mod)
|
||||
end end
|
||||
local modules_list = {}
|
||||
@ -94,17 +93,23 @@ end
|
||||
-- @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.policies[module_slug][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
|
||||
self.org:approve(
|
||||
approval_module,
|
||||
self,
|
||||
{prompt = "Update " .. policy .. " policy on module " ..
|
||||
module_slug .. " with: " .. input .. " ?"},
|
||||
function()
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"Updating " .. policy .. " policy on module " ..
|
||||
module_slug .. " with: " .. 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
|
||||
self.org:delete_process(self.id)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
modpol.modules.change_policy = change_policy
|
||||
|
@ -34,6 +34,8 @@ function display_policies:initiate(result)
|
||||
elseif type(v2) == "table"
|
||||
or type(v2) == "number" then
|
||||
v2_string = tostring(v2)
|
||||
elseif type(v2) == "boolean" then
|
||||
v2_string = tostring(v2)
|
||||
else
|
||||
v2_string = "Could not render"
|
||||
end
|
||||
|
@ -64,6 +64,36 @@ function modpol.orgs:call_module(module_slug, initiator, config, result, parent_
|
||||
return index
|
||||
end
|
||||
|
||||
--- Generic approval check for modules, able to call other modules
|
||||
-- @function modpol.orgs.approve
|
||||
-- @param approval_module Slug of module used to approve, or nil
|
||||
-- @param process The parent process of which this is part
|
||||
-- @param config Config for module
|
||||
-- @param result Function for what gets done if approved
|
||||
function modpol.orgs:approve(approval_module, process, config, result)
|
||||
if not approval_module then -- if nil then simply approve
|
||||
result()
|
||||
return
|
||||
elseif not modpol.modules[approval_module] then
|
||||
modpol.interactions.message(
|
||||
process.initiator,
|
||||
"Approval process failed: module " .. approval_module
|
||||
.. " does not exist.")
|
||||
modpol.interactions.org_dashboard(
|
||||
process.initiator, process.org.id)
|
||||
process.org:delete_process(process.id)
|
||||
return
|
||||
else
|
||||
-- call module
|
||||
modpol.orgs:call_module(
|
||||
approval_module,
|
||||
process.initiator,
|
||||
config,
|
||||
result, process.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Get the root process of the given id
|
||||
-- @function modpol.orgs.get_root_process
|
||||
-- @param id
|
||||
@ -76,7 +106,7 @@ function modpol.orgs:get_root_process(id)
|
||||
return process
|
||||
end
|
||||
|
||||
--- Delete the process given id
|
||||
--- Delete the process given id, return to dashboard
|
||||
-- @function modpol.orgs.delete_process
|
||||
-- @param id
|
||||
function modpol.orgs:delete_process(id)
|
||||
@ -97,6 +127,7 @@ function modpol.orgs:delete_process(id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Delete process tree by id
|
||||
-- @function modpol.orgs:delete_process_tree
|
||||
-- @param id Id of process tree
|
||||
|
Loading…
x
Reference in New Issue
Block a user