moving how pending actions work around, after some testing and discussion. reordered how new processes are created so that they have access to their own ids
This commit is contained in:
parent
1890534195
commit
f616136597
@ -8,9 +8,9 @@ modpol.modules.consent.__index = modpol.modules.consent
|
||||
function temp_consent_process()
|
||||
return {
|
||||
type = "consent",
|
||||
id = nil,
|
||||
org_id = nil,
|
||||
request_id = nil,
|
||||
actions = {},
|
||||
total_votes = 0,
|
||||
majority_to_pass = 0.51,
|
||||
votes_yes = {},
|
||||
@ -20,23 +20,20 @@ end
|
||||
|
||||
-- ===============================================
|
||||
-- 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()
|
||||
process.id = id
|
||||
process.request_id = request_id
|
||||
process.org_id = org_id
|
||||
|
||||
setmetatable(process, modpol.modules.consent)
|
||||
modpol.ocutil.log('Created new process for request id #' .. request_id)
|
||||
|
||||
-- adding new pending action for all users in the org to vote on the request
|
||||
local process_org = modpol.orgs.get_org(org_id)
|
||||
for k, member in ipairs(process_org.members) do
|
||||
process.actions[member] = {'approve'}
|
||||
end
|
||||
|
||||
return process
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- =========================================
|
||||
-- function to delete a process, called when process finishes
|
||||
function modpol.modules.consent:delete()
|
||||
|
@ -14,6 +14,7 @@ function temp_org()
|
||||
policies = {},
|
||||
processes = {},
|
||||
requests = {},
|
||||
pending = {},
|
||||
members = {},
|
||||
parent = nil,
|
||||
children = {}
|
||||
|
@ -13,10 +13,6 @@ function modpol.orgs:create_process(process_type, request_id)
|
||||
return
|
||||
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)
|
||||
for k, v in ipairs(self.processes) do
|
||||
if v == 'deleted' then
|
||||
@ -28,17 +24,33 @@ function modpol.orgs:create_process(process_type, request_id)
|
||||
local index
|
||||
-- attempts to fill empty spots in list, otherwise appends to end
|
||||
if empty_index then
|
||||
self.processes[empty_index] = new_process
|
||||
index = empty_index
|
||||
else
|
||||
table.insert(self.processes, new_process)
|
||||
index = #self.processes
|
||||
index = #self.processes + 1
|
||||
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
|
||||
end
|
||||
|
||||
-- ===========================
|
||||
-- adds a new pending action to the org's table
|
||||
function modpol.orgs:add_pending_action(user, process_id, action)
|
||||
self.pending[user][process_id] = action
|
||||
|
||||
-- pending = {
|
||||
-- ['lukvmil']={
|
||||
-- [1]='approve'
|
||||
-- }
|
||||
-- }
|
||||
|
||||
end
|
||||
|
||||
-- ===========================
|
||||
-- compares to requests to see if they are identical
|
||||
function modpol.orgs.comp_req(req1, req2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user