Merge branch 'actions' into 'master'
adding pending actions control flow See merge request medlabboulder/modpol!25
This commit is contained in:
commit
0539b82d9a
@ -78,9 +78,9 @@ if (modpol.orgs.array) then
|
|||||||
if type(org) == 'table' then
|
if type(org) == 'table' then
|
||||||
setmetatable(org, modpol.orgs)
|
setmetatable(org, modpol.orgs)
|
||||||
-- sets process metatable on load
|
-- sets process metatable on load
|
||||||
if type(org.processes) == 'table' then
|
for id, process in ipairs(org.processes) do
|
||||||
for id, process in ipairs(org.processes) do
|
if type(process) == 'table' then
|
||||||
setmetatable(process, modpol.modules[process.type])
|
setmetatable(process, modpol.modules[process.type])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,6 +8,7 @@ modpol.modules.consent.__index = modpol.modules.consent
|
|||||||
function temp_consent_process()
|
function temp_consent_process()
|
||||||
return {
|
return {
|
||||||
type = "consent",
|
type = "consent",
|
||||||
|
id = nil,
|
||||||
org_id = nil,
|
org_id = nil,
|
||||||
request_id = nil,
|
request_id = nil,
|
||||||
total_votes = 0,
|
total_votes = 0,
|
||||||
@ -19,21 +20,31 @@ end
|
|||||||
|
|
||||||
-- ===============================================
|
-- ===============================================
|
||||||
-- function to create a new consent process to resolve a pending process
|
-- function to create a new consent process to resolve a pending process
|
||||||
function modpol.modules.consent:new_process(request_id, org_id)
|
function modpol.modules.consent:new_process(id, request_id, org_id)
|
||||||
local process = temp_consent_process()
|
local process = temp_consent_process()
|
||||||
|
process.id = id
|
||||||
process.request_id = request_id
|
process.request_id = request_id
|
||||||
process.org_id = org_id
|
process.org_id = org_id
|
||||||
|
|
||||||
setmetatable(process, modpol.modules.consent)
|
setmetatable(process, modpol.modules.consent)
|
||||||
modpol.ocutil.log('Created new process for request id #' .. request_id)
|
modpol.ocutil.log('Created new process #' .. id .. ' for request id #' .. request_id)
|
||||||
|
|
||||||
|
-- modpol.orgs.get_org(self.org_id):add_pending_action('luke', self.id, 'approve')
|
||||||
|
local p_org = modpol.orgs.get_org(org_id)
|
||||||
|
|
||||||
|
for i, member in ipairs(p_org.members) do
|
||||||
|
p_org:add_pending_action(id, member, 'approve')
|
||||||
|
end
|
||||||
|
|
||||||
return process
|
return process
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- =========================================
|
-- =========================================
|
||||||
-- function to delete a process, called when process finishes
|
-- function to delete a process, called when process finishes
|
||||||
function modpol.modules.consent:delete()
|
function modpol.modules.consent:delete()
|
||||||
local process_org = modpol.orgs.get_org(self.org_id)
|
local process_org = modpol.orgs.get_org(self.org_id)
|
||||||
|
process_org:wipe_pending_actions(self.id)
|
||||||
process_org.processes[self.id] = "deleted"
|
process_org.processes[self.id] = "deleted"
|
||||||
modpol.ocutil.log('Deleted process #' .. self.id)
|
modpol.ocutil.log('Deleted process #' .. self.id)
|
||||||
end
|
end
|
||||||
@ -55,6 +66,9 @@ function modpol.modules.consent:approve(user, decision)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.total_votes = self.total_votes + 1
|
self.total_votes = self.total_votes + 1
|
||||||
|
|
||||||
|
local p_org = modpol.orgs.get_org(self.org_id)
|
||||||
|
p_org:remove_pending_action(self.id, user, "approve")
|
||||||
|
|
||||||
self:update_status()
|
self:update_status()
|
||||||
end
|
end
|
||||||
@ -77,8 +91,4 @@ function modpol.modules.consent:update_status()
|
|||||||
else
|
else
|
||||||
modpol.ocutil.log('Waiting for more votes...')
|
modpol.ocutil.log('Waiting for more votes...')
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function modpol.modules.consent.pending_processes()
|
|
||||||
|
|
||||||
end
|
end
|
@ -14,6 +14,7 @@ function temp_org()
|
|||||||
policies = {},
|
policies = {},
|
||||||
processes = {},
|
processes = {},
|
||||||
requests = {},
|
requests = {},
|
||||||
|
pending = {},
|
||||||
members = {},
|
members = {},
|
||||||
parent = nil,
|
parent = nil,
|
||||||
children = {}
|
children = {}
|
||||||
|
@ -13,10 +13,6 @@ function modpol.orgs:create_process(process_type, request_id)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- retrieving requested module
|
|
||||||
local module = modpol.modules[process_type]
|
|
||||||
local new_process = module:new_process(request_id, self.id)
|
|
||||||
|
|
||||||
-- linear search for empty process slots (lazy deletion)
|
-- linear search for empty process slots (lazy deletion)
|
||||||
for k, v in ipairs(self.processes) do
|
for k, v in ipairs(self.processes) do
|
||||||
if v == 'deleted' then
|
if v == 'deleted' then
|
||||||
@ -28,17 +24,60 @@ function modpol.orgs:create_process(process_type, request_id)
|
|||||||
local index
|
local index
|
||||||
-- attempts to fill empty spots in list, otherwise appends to end
|
-- attempts to fill empty spots in list, otherwise appends to end
|
||||||
if empty_index then
|
if empty_index then
|
||||||
self.processes[empty_index] = new_process
|
|
||||||
index = empty_index
|
index = empty_index
|
||||||
else
|
else
|
||||||
table.insert(self.processes, new_process)
|
index = #self.processes + 1
|
||||||
index = #self.processes
|
|
||||||
end
|
end
|
||||||
|
|
||||||
new_process.id = index
|
-- retrieving requested module
|
||||||
|
local module = modpol.modules[process_type]
|
||||||
|
local new_process = module:new_process(index, request_id, self.id)
|
||||||
|
|
||||||
|
self.processes[index] = new_process
|
||||||
|
|
||||||
return index
|
return index
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ===========================
|
||||||
|
-- adds a new pending action to the org's table
|
||||||
|
function modpol.orgs:add_pending_action(process_id, user, action)
|
||||||
|
-- adds tables if they don't exist already
|
||||||
|
self.pending[user] = self.pending[user] or {}
|
||||||
|
self.pending[user][process_id] = self.pending[user][process_id] or {}
|
||||||
|
|
||||||
|
-- inserting actual action
|
||||||
|
table.insert(self.pending[user][process_id], action)
|
||||||
|
modpol.ocutil.log("Added pending action '" .. action .. "' to " .. user .. " in process #" .. process_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ========================
|
||||||
|
-- removes a pending action from the org's table
|
||||||
|
function modpol.orgs:remove_pending_action(process_id, user, action)
|
||||||
|
-- cautiously checks if pending action exists before removing it
|
||||||
|
if self.pending[user] then
|
||||||
|
if self.pending[user][process_id] then
|
||||||
|
-- searching for action to remove
|
||||||
|
for i, a in pairs(self.pending[user][process_id]) do
|
||||||
|
if a == action then
|
||||||
|
self.pending[user][process_id][i] = nil
|
||||||
|
modpol.ocutil.log("Removed pending action '" .. action .. "' from " .. user .. " in process #" .. process_id)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
modpol.ocutil.log("Could not remove pending action '" .. action .. "' from " .. user .. " in process #" .. process_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- =====================
|
||||||
|
-- removes all pending actions for a given process id from all users
|
||||||
|
function modpol.orgs:wipe_pending_actions(process_id)
|
||||||
|
for user in pairs(self.pending) do
|
||||||
|
self.pending[user][process_id] = nil
|
||||||
|
end
|
||||||
|
modpol.ocutil.log("Removed all pending actions for process #" .. process_id)
|
||||||
|
end
|
||||||
|
|
||||||
-- ===========================
|
-- ===========================
|
||||||
-- compares to requests to see if they are identical
|
-- compares to requests to see if they are identical
|
||||||
function modpol.orgs.comp_req(req1, req2)
|
function modpol.orgs.comp_req(req1, req2)
|
||||||
|
@ -33,13 +33,14 @@ new_request = {
|
|||||||
params = {"new_org"}
|
params = {"new_org"}
|
||||||
}
|
}
|
||||||
|
|
||||||
request_id = modpol.instance:make_request(new_request)
|
|
||||||
|
|
||||||
modpol.instance:add_member('luke')
|
modpol.instance:add_member('luke')
|
||||||
modpol.instance:add_member('josh')
|
modpol.instance:add_member('josh')
|
||||||
modpol.instance:add_member('nathan')
|
modpol.instance:add_member('nathan')
|
||||||
|
|
||||||
|
request_id = modpol.instance:make_request(new_request)
|
||||||
|
|
||||||
for id, process in ipairs(modpol.instance.processes) do
|
for id, process in ipairs(modpol.instance.processes) do
|
||||||
process:approve('luke', true)
|
-- process:approve('luke', true)
|
||||||
process:approve('josh', true)
|
process:approve('josh', true)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user