functional test of call_module and new pending action/interact version
This commit is contained in:
parent
08151ad9d9
commit
fa7a0f82f6
@ -7,9 +7,7 @@ dofile (localdir .. "/users/users.lua")
|
|||||||
|
|
||||||
--orgs
|
--orgs
|
||||||
dofile (localdir .. "/orgs/base.lua")
|
dofile (localdir .. "/orgs/base.lua")
|
||||||
dofile (localdir .. "/orgs/requests.lua")
|
dofile (localdir .. "/orgs/process.lua")
|
||||||
dofile (localdir .. "/orgs/consent.lua")
|
|
||||||
dofile (localdir .. "/orgs/defer.lua")
|
|
||||||
|
|
||||||
--interactions
|
--interactions
|
||||||
dofile (localdir .. "/interactions/interactions.lua")
|
dofile (localdir .. "/interactions/interactions.lua")
|
||||||
|
@ -11,7 +11,8 @@ function JoinOrg.create(initiator, org, id)
|
|||||||
desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.",
|
desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.",
|
||||||
initiator = initiator,
|
initiator = initiator,
|
||||||
org = org,
|
org = org,
|
||||||
id = id
|
id = id,
|
||||||
|
votes_yes = 0
|
||||||
}
|
}
|
||||||
setmetatable(inst, JoinOrg_mt)
|
setmetatable(inst, JoinOrg_mt)
|
||||||
return inst
|
return inst
|
||||||
@ -24,63 +25,27 @@ function JoinOrg:initiate(result)
|
|||||||
"Would you like to join",
|
"Would you like to join",
|
||||||
function (resp)
|
function (resp)
|
||||||
if resp == "Yes" then
|
if resp == "Yes" then
|
||||||
|
for id, member in pairs(self.org.members) do
|
||||||
modpol.call_module(
|
self.org:add_pending_action(self.id, member, "callback")
|
||||||
"consent",
|
|
||||||
"",
|
end
|
||||||
org,
|
|
||||||
result
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
modpol.modules.consent(
|
|
||||||
"Let " .. initiator .. " join " .. org.name .. "?",
|
|
||||||
org,
|
|
||||||
params,
|
|
||||||
self:on_failure,
|
|
||||||
self:on_success
|
|
||||||
)
|
|
||||||
|
|
||||||
-- for i, member in ipairs(org.members) do
|
|
||||||
-- org:add_pending_action(
|
|
||||||
-- member,
|
|
||||||
-- function ()
|
|
||||||
-- modpol.interactions.binary_poll_user(
|
|
||||||
-- member,
|
|
||||||
-- "Let " .. initiator .. " join " .. org.name .. "?",
|
|
||||||
-- function (resp)
|
|
||||||
-- self:vote()
|
|
||||||
-- end
|
|
||||||
-- )
|
|
||||||
-- end
|
|
||||||
-- )
|
|
||||||
-- end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
for user in pairs(self.org.users) {
|
|
||||||
self.org:add_pending_action(self.id, user, "callback")
|
|
||||||
|
|
||||||
|
|
||||||
org.pending.user[2348] = "callback"
|
|
||||||
|
|
||||||
self:callback(user)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if result then result() end
|
if result then result() end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function JoinOrg:callback(user)
|
function JoinOrg:callback(member)
|
||||||
modpol.interactions.binary_poll_user(
|
modpol.interactions.binary_poll_user(
|
||||||
self.initiator,
|
member,
|
||||||
"Do you want this" .. self.user_to_add .. "to join?",
|
"Do you want " .. self.initiator .. " to join?",
|
||||||
function (resp)
|
function (resp)
|
||||||
if resp == "yes" then
|
if resp == "Yes" then
|
||||||
self.votes_yes += 1
|
self.votes_yes = self.votes_yes + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
self:evaluate_vote()
|
self:evaluate_vote()
|
||||||
@ -91,9 +56,12 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function JoinOrg:on_success()
|
function JoinOrg:evaluate_vote()
|
||||||
self.org:add_member(self.initiator)
|
if self.votes_yes >= 1 then
|
||||||
self.org:delete_process(self.id)
|
print('added user')
|
||||||
|
self.org:add_member(self.initiator)
|
||||||
|
self.org:wipe_pending_actions(self.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ===================================
|
-- ===================================
|
||||||
|
48
modpol/orgs/example.lua
Normal file
48
modpol/orgs/example.lua
Normal 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)
|
||||||
|
}
|
@ -26,6 +26,8 @@ function modpol.orgs:call_module(module_name, initiator)
|
|||||||
|
|
||||||
self.processes[index] = new_process
|
self.processes[index] = new_process
|
||||||
|
|
||||||
|
self.processes[index]:initiate()
|
||||||
|
|
||||||
return index
|
return index
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ function modpol.orgs:add_pending_action(process_id, user, callback)
|
|||||||
self.pending[user][process_id] = callback
|
self.pending[user][process_id] = callback
|
||||||
end
|
end
|
||||||
|
|
||||||
function mopdol.orgs:remove_pending_action(process_id, user)
|
function modpol.orgs:remove_pending_action(process_id, user)
|
||||||
if self.pending[user] then
|
if self.pending[user] then
|
||||||
self.pending[user][process_id] = nil
|
self.pending[user][process_id] = nil
|
||||||
end
|
end
|
||||||
@ -69,7 +71,7 @@ function modpol.orgs:interact(process_id, user)
|
|||||||
if self.pending[user] then
|
if self.pending[user] then
|
||||||
local callback = self.pending[user][process_id]
|
local callback = self.pending[user][process_id]
|
||||||
if callback then
|
if callback then
|
||||||
process[callback](process)
|
process[callback](process, user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -7,11 +7,9 @@ test_org:add_member('nathan')
|
|||||||
|
|
||||||
print(table.concat(test_org:list_members(), ", "))
|
print(table.concat(test_org:list_members(), ", "))
|
||||||
|
|
||||||
function completion()
|
-- modpol.modules.join_org.initiate("paul", test_org)
|
||||||
print("completed")
|
|
||||||
end
|
|
||||||
|
|
||||||
modpol.modules.join_org.initiate("paul", test_org, completion)
|
test_org:call_module(
|
||||||
|
"join_org_class",
|
||||||
-- process = modpol.modules.join_org_class.create("paul", test_org)
|
"paul"
|
||||||
-- process:initiate(completion)
|
)
|
Loading…
x
Reference in New Issue
Block a user