Created defer_consent module
This commit is contained in:
@ -15,10 +15,11 @@ dofile (localdir .. "/interactions/interactions.lua")
|
||||
dofile (localdir .. "/modules/add_child_org_consent.lua")
|
||||
dofile (localdir .. "/modules/change_modules.lua")
|
||||
dofile (localdir .. "/modules/consent.lua")
|
||||
dofile (localdir .. "/modules/defer_consent.lua")
|
||||
dofile (localdir .. "/modules/join_org_consent.lua")
|
||||
dofile (localdir .. "/modules/leave_org.lua")
|
||||
dofile (localdir .. "/modules/message_org.lua")
|
||||
dofile (localdir .. "/modules/random.lua")
|
||||
dofile (localdir .. "/modules/randomizer.lua")
|
||||
dofile (localdir .. "/modules/remove_child_consent.lua")
|
||||
dofile (localdir .. "/modules/remove_member_consent.lua")
|
||||
dofile (localdir .. "/modules/remove_org_consent.lua")
|
||||
|
@ -26,7 +26,6 @@ function add_child_org_consent:initiate(result)
|
||||
modpol.interactions.org_dashboard(
|
||||
self.initiator, self.org.name)
|
||||
self.org:delete_process(self.id)
|
||||
if result then result() end
|
||||
return
|
||||
elseif modpol.orgs.get_org(input) then
|
||||
modpol.interactions.message(
|
||||
|
@ -23,7 +23,7 @@ function consent:initiate(result)
|
||||
if self.org:get_member_count() == 0 then
|
||||
if self.data.result then
|
||||
self.data.result() end
|
||||
self.org:wipe_pending_actions(self.id)
|
||||
self.org:delete_process(self.id)
|
||||
else
|
||||
-- otherwise, create poll
|
||||
for id, member in pairs(self.org.members) do
|
||||
@ -44,7 +44,6 @@ function consent:callback(member)
|
||||
if self.data.votes >= self.config.votes_required then
|
||||
if self.data.result then
|
||||
self.data.result() end
|
||||
self.org:wipe_pending_actions(self.id)
|
||||
self.org:delete_process(self.id)
|
||||
end
|
||||
modpol.interactions.org_dashboard(
|
||||
|
57
modpol_core/modules/defer_consent.lua
Normal file
57
modpol_core/modules/defer_consent.lua
Normal file
@ -0,0 +1,57 @@
|
||||
--- defer_consent
|
||||
-- @module defer_consent
|
||||
|
||||
--- (Required): data table containing name and description of the module
|
||||
-- @field name "Human-readable name (parens OK, no brackets)"
|
||||
-- @field slug "Same as module class name"
|
||||
-- @field desc "Description of the module"
|
||||
-- @field hide "Whether this is a hidden utility module"
|
||||
local defer_consent = {
|
||||
name = "Defer consent",
|
||||
slug = "defer_consent",
|
||||
desc = "Defers consent on a decision to another org",
|
||||
hide = true;
|
||||
}
|
||||
|
||||
--- (Required) Data for module
|
||||
-- Variables that module uses during the course of a process
|
||||
-- Can be blank
|
||||
defer_consent.data = {
|
||||
}
|
||||
|
||||
--- (Required): config for module
|
||||
-- @field defer_org Name or ID of target org
|
||||
-- @field votes_required Threshold passed on to `consent`
|
||||
-- @field prompt String passed on to `consent`
|
||||
defer_consent.config = {
|
||||
defer_org = "Root",
|
||||
votes_required = 1,
|
||||
prompt = "Do you consent?"
|
||||
}
|
||||
|
||||
--- (Required): initiate function
|
||||
-- @param result (optional) Callback if this module is embedded in other modules
|
||||
-- @function initiate
|
||||
function defer_consent:initiate(result)
|
||||
local defer_org = modpol.orgs.get_org(self.config.defer_org)
|
||||
if not defer_org then
|
||||
modpol.interactions.message(
|
||||
self.initiator, "Target org not found, aborting")
|
||||
self.org:delete_process(self.id)
|
||||
else
|
||||
defer_org:call_module(
|
||||
"consent", self.initiator,
|
||||
{
|
||||
votes_required = self.config.votes_required,
|
||||
prompt = self.config.prompt
|
||||
},
|
||||
function()
|
||||
if result then result() end
|
||||
end)
|
||||
end
|
||||
if result then result() end
|
||||
self.org:delete_process(self.id)
|
||||
end
|
||||
|
||||
--- (Required) Add to module table
|
||||
modpol.modules.defer_consent = defer_consent
|
@ -25,7 +25,6 @@ function randomizer:initiate(result)
|
||||
if #self.data.options_table == 0 or self.config.num_results == 0 then
|
||||
if self.data.result then
|
||||
self.data.result({}) end
|
||||
self.org:wipe_pending_actions(self.id)
|
||||
self.org:delete_process(self.id)
|
||||
else
|
||||
-- otherwise, choose a random result
|
||||
|
@ -43,10 +43,11 @@ function module_template:initiate(result)
|
||||
-- call interaction functions here!
|
||||
|
||||
-- concluding functions:
|
||||
-- call these wherever process might end;
|
||||
|
||||
-- may need to put result in self.data.result
|
||||
-- if process ends in another function
|
||||
-- call this when module is successful (not for abort):
|
||||
if result then result() end
|
||||
-- call this wherever process might end:
|
||||
self.org:delete_process(self.id)
|
||||
end
|
||||
|
||||
|
@ -53,7 +53,8 @@ function modpol.orgs:call_module(module_slug, initiator, config, result)
|
||||
return index
|
||||
end
|
||||
|
||||
function modpol.orgs:delete_process(id)
|
||||
function modpol.orgs:delete_process(id)
|
||||
self:wipe_pending_actions(id)
|
||||
self.processes[id] = 'deleted'
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user