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:
Luke Miller 2021-06-13 14:22:07 -04:00
parent 1890534195
commit f616136597
3 changed files with 26 additions and 16 deletions

View File

@ -8,9 +8,9 @@ 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,
actions = {},
total_votes = 0, total_votes = 0,
majority_to_pass = 0.51, majority_to_pass = 0.51,
votes_yes = {}, votes_yes = {},
@ -20,23 +20,20 @@ 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 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 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()

View File

@ -14,6 +14,7 @@ function temp_org()
policies = {}, policies = {},
processes = {}, processes = {},
requests = {}, requests = {},
pending = {},
members = {}, members = {},
parent = nil, parent = nil,
children = {} children = {}

View File

@ -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,33 @@ 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(user, process_id, action)
self.pending[user][process_id] = action
-- pending = {
-- ['lukvmil']={
-- [1]='approve'
-- }
-- }
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)