functional test of call_module and new pending action/interact version

This commit is contained in:
Luke Miller
2021-12-06 16:45:52 -05:00
parent 08151ad9d9
commit fa7a0f82f6
5 changed files with 75 additions and 61 deletions
+48
View File
@@ -0,0 +1,48 @@
--[[
modpol calls this function when someone starts a new request for this module
--]]
function module:initiate(org) {
form = {
{
"name": "to_remove",
"display": "Which user should be removed?",
"type": "drop-down",
"values": org:list_members()
},
{
"name": "reason",
"type": "text-box",
"prompt": "Reason for removing member:"
}
}
return form
}
--[[
modpol prompts the user with this form, and after receiving the data asynchronously
the returned form would look like:
{
"to_remove": luke,
"reason": stealing food
}
based on provided "name" fields and the input given by the user
now module:request is called
--]]
function module:request(form) {
self.data = form
}
--[[
after the module request function runs, modpol will initiate the consent process
if consent is approved, the implement function is called
--]]
function module:implement() {
org:remove_member(self.data.to_remove)
}
+4 -2
View File
@@ -26,6 +26,8 @@ function modpol.orgs:call_module(module_name, initiator)
self.processes[index] = new_process
self.processes[index]:initiate()
return index
end
@@ -38,7 +40,7 @@ function modpol.orgs:add_pending_action(process_id, user, callback)
self.pending[user][process_id] = callback
end
function mopdol.orgs:remove_pending_action(process_id, user)
function modpol.orgs:remove_pending_action(process_id, user)
if self.pending[user] then
self.pending[user][process_id] = nil
end
@@ -69,7 +71,7 @@ function modpol.orgs:interact(process_id, user)
if self.pending[user] then
local callback = self.pending[user][process_id]
if callback then
process[callback](process)
process[callback](process, user)
end
end
end