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
|
## 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).
|
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 = {
|
change_policy.data = {
|
||||||
result = nil
|
result = false
|
||||||
}
|
}
|
||||||
|
|
||||||
change_policy.config = {
|
change_policy.config = {
|
||||||
approval = "none"
|
approval_module = false
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Change modules initiate
|
--- Change modules initiate
|
||||||
@ -23,8 +23,7 @@ function change_policy:initiate(result)
|
|||||||
-- prepare module options
|
-- prepare module options
|
||||||
local available_modules = {}
|
local available_modules = {}
|
||||||
for k,org_mod in pairs(modpol.modules) do
|
for k,org_mod in pairs(modpol.modules) do
|
||||||
if not org_mod.hide and
|
if self.org.policies[k] then
|
||||||
self.org.policies[k] then
|
|
||||||
available_modules[org_mod.slug] = modpol.util.copy_table(org_mod)
|
available_modules[org_mod.slug] = modpol.util.copy_table(org_mod)
|
||||||
end end
|
end end
|
||||||
local modules_list = {}
|
local modules_list = {}
|
||||||
@ -94,17 +93,23 @@ end
|
|||||||
-- @param policy (string) policy slug
|
-- @param policy (string) policy slug
|
||||||
-- @param input (string) input content
|
-- @param input (string) input content
|
||||||
function change_policy:approve_change(module_slug, policy, input)
|
function change_policy:approve_change(module_slug, policy, input)
|
||||||
-- NEED TO ADD APPROVAL CODE for consent, etc.
|
self.org:approve(
|
||||||
modpol.interactions.message(
|
approval_module,
|
||||||
self.initiator,
|
self,
|
||||||
"Updating " .. policy .. " policy on module " ..
|
{prompt = "Update " .. policy .. " policy on module " ..
|
||||||
module_slug .. " with: " .. input)
|
module_slug .. " with: " .. input .. " ?"},
|
||||||
self.org.policies[module_slug][policy] = input
|
function()
|
||||||
modpol.interactions.org_dashboard(
|
modpol.interactions.message(
|
||||||
self.initiator, self.org.id)
|
self.initiator,
|
||||||
if self.data.result then self.data.result() end
|
"Updating " .. policy .. " policy on module " ..
|
||||||
self.org:delete_process(self.id)
|
module_slug .. " with: " .. input)
|
||||||
return
|
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
|
end
|
||||||
|
|
||||||
modpol.modules.change_policy = change_policy
|
modpol.modules.change_policy = change_policy
|
||||||
|
@ -34,6 +34,8 @@ function display_policies:initiate(result)
|
|||||||
elseif type(v2) == "table"
|
elseif type(v2) == "table"
|
||||||
or type(v2) == "number" then
|
or type(v2) == "number" then
|
||||||
v2_string = tostring(v2)
|
v2_string = tostring(v2)
|
||||||
|
elseif type(v2) == "boolean" then
|
||||||
|
v2_string = tostring(v2)
|
||||||
else
|
else
|
||||||
v2_string = "Could not render"
|
v2_string = "Could not render"
|
||||||
end
|
end
|
||||||
|
@ -64,6 +64,36 @@ function modpol.orgs:call_module(module_slug, initiator, config, result, parent_
|
|||||||
return index
|
return index
|
||||||
end
|
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
|
--- Get the root process of the given id
|
||||||
-- @function modpol.orgs.get_root_process
|
-- @function modpol.orgs.get_root_process
|
||||||
-- @param id
|
-- @param id
|
||||||
@ -76,7 +106,7 @@ function modpol.orgs:get_root_process(id)
|
|||||||
return process
|
return process
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Delete the process given id
|
--- Delete the process given id, return to dashboard
|
||||||
-- @function modpol.orgs.delete_process
|
-- @function modpol.orgs.delete_process
|
||||||
-- @param id
|
-- @param id
|
||||||
function modpol.orgs:delete_process(id)
|
function modpol.orgs:delete_process(id)
|
||||||
@ -97,6 +127,7 @@ function modpol.orgs:delete_process(id)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Delete process tree by id
|
--- Delete process tree by id
|
||||||
-- @function modpol.orgs:delete_process_tree
|
-- @function modpol.orgs:delete_process_tree
|
||||||
-- @param id Id of process tree
|
-- @param id Id of process tree
|
||||||
|
Loading…
x
Reference in New Issue
Block a user