added consent module, nesting mdoules now functional!

This commit is contained in:
Luke Miller
2021-12-16 16:52:06 -05:00
parent 0b265d7be5
commit 48123b3496
6 changed files with 100 additions and 42 deletions

View File

@ -15,5 +15,7 @@ dofile (localdir .. "/interactions/interactions.lua")
--modules --modules
dofile (localdir .. "/modules/join_org.lua") dofile (localdir .. "/modules/join_org.lua")
dofile (localdir .. "/modules/join_org_class.lua") dofile (localdir .. "/modules/join_org_class.lua")
dofile (localdir .. "/modules/join_org_consent.lua")
dofile (localdir .. "/modules/consent.lua")
dofile (localdir .. "/modules/remove_org.lua") dofile (localdir .. "/modules/remove_org.lua")
dofile (localdir .. "/modules/child_org.lua") dofile (localdir .. "/modules/child_org.lua")

View File

@ -0,0 +1,42 @@
Consent = {}
Consent.setup = {
name = "Consent",
slug = "consent",
desc = "Other modules can use to implement consent based decision making",
votes = 0
}
Consent.config = {
prompt = "Would you like to approve this action?",
votes_required = 1
}
function Consent:initiate(result)
self.result = result
for id, member in pairs(self.org.members) do
self.org:add_pending_action(self.id, member, "callback")
end
end
function Consent:callback(member)
modpol.interactions.binary_poll_user(
member,
self.config.prompt,
function (resp)
if resp == "Yes" then
self.votes = self.votes + 1
end
if self.votes >= self.config.votes_required then
self.result()
self.org:wipe_pending_actions(self.id)
end
end
)
end
modpol.modules.consent = Consent

View File

@ -0,0 +1,30 @@
JoinOrg = {}
JoinOrg.setup = {
name = "Join an org",
slug = "join_org_consent",
desc = "Consent based join org module"
}
function JoinOrg:initiate()
self.org:call_module(
"consent",
self.initiator,
{
prompt = "Allow " .. self.initiator .. " to join?",
votes_required = 1
},
function ()
self:complete()
end
)
end
function JoinOrg:complete()
self.org:add_member(self.initiator)
print("Added " .. self.initiator .. " to the org!")
end
modpol.modules.join_org_consent = JoinOrg

View File

@ -1,6 +1,6 @@
function modpol.orgs:call_module(module_name, initiator, config, result) function modpol.orgs:call_module(module_name, initiator, config, result)
if not modpol.modules[module_name] then if not modpol.modules[module_name] then
modpol.ocutil.log('Error in ' .. self.name .. ':call_module -> module "' .. name .. '" not found') modpol.ocutil.log('Error in ' .. self.name .. ':call_module -> module "' .. module_name .. '" not found')
return return
end end
@ -23,12 +23,22 @@ function modpol.orgs:call_module(module_name, initiator, config, result)
local module = modpol.modules[module_name] local module = modpol.modules[module_name]
-- sets default values for undeclared config variables
if module.config then
for k, v in pairs(module.config) do
if config[k] == nil then
config[k] = v
end
end
end
-- setting default params -- setting default params
local new_process = { local new_process = {
metatable = {__index = module}, metatable = {__index = module},
initiator = initiator, initiator = initiator,
org = self, org = self,
id = index id = index,
config = config
} }
-- copying default fields from setup -- copying default fields from setup
@ -39,15 +49,7 @@ function modpol.orgs:call_module(module_name, initiator, config, result)
setmetatable(new_process, new_process.metatable) setmetatable(new_process, new_process.metatable)
self.processes[index] = new_process self.processes[index] = new_process
self.processes[index]:initiate(result)
-- sets default values for undeclared config variables
for k, v in pairs(module.config) do
if config[k] == nil then
config[k] = v
end
end
self.processes[index]:initiate(config, result))
return index return index
end end

View File

@ -1,31 +0,0 @@
dofile("../modpol.lua")
print('\nRemoving existing orgs')
modpol.orgs.reset()
print('\nCreating an org called "test_org"')
test_org = modpol.instance:add_org('test_org', 'luke')
print('\nAdding user "nathan" to test_org')
test_org:add_member('nathan')
print("\nOkay, let's start with requests. Setting up an org...")
modpol.instance:add_org('test_org', 'luke')
test_org:add_member('nathan')
print('\nMaking consent the add_member policy')
test_org:set_policy("add_member", "consent", false);
print('\nMaking a request to add Josh')
add_josh = {
user = "josh",
type = "add_member",
params = {"josh"}
}
request_id = test_org:make_request(add_josh)
print('\nHave the two members vote on it')
modpol.interactions.org_dashboard("nathan","test_org")
modpol.interactions.org_dashboard("luke","test_org")

View File

@ -0,0 +1,13 @@
dofile('../modpol.lua');
modpol.orgs.reset()
test_org = modpol.instance:add_org('test_org', 'luke')
test_org:add_member('nathan')
print(table.concat(test_org:list_members(), ", "))
test_org:call_module(
"join_org_consent",
"paul"
)