added remove pending action function, now called in consent module when pending action is completed

This commit is contained in:
Luke Miller 2021-06-13 15:06:47 -04:00
parent 2e6c8a5ee3
commit 295cd983b8
2 changed files with 35 additions and 9 deletions

View File

@ -29,11 +29,17 @@ function modpol.modules.consent:new_process(id, request_id, org_id)
setmetatable(process, modpol.modules.consent)
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
end
-- =========================================
-- function to delete a process, called when process finishes
function modpol.modules.consent:delete()
@ -59,6 +65,9 @@ function modpol.modules.consent:approve(user, decision)
end
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()
end

View File

@ -40,17 +40,34 @@ 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'
-- }
-- }
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)
if self.pending[user] then
if self.pending[user][process_id] then
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
-- ===========================
-- compares to requests to see if they are identical
function modpol.orgs.comp_req(req1, req2)