diff --git a/modpol/modules/consent.lua b/modpol/modules/consent.lua index 18c3673..ff02e71 100644 --- a/modpol/modules/consent.lua +++ b/modpol/modules/consent.lua @@ -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() diff --git a/modpol/orgs/base.lua b/modpol/orgs/base.lua index 1a975a6..2b8fbf5 100644 --- a/modpol/orgs/base.lua +++ b/modpol/orgs/base.lua @@ -14,6 +14,7 @@ function temp_org() policies = {}, processes = {}, requests = {}, + pending = {}, members = {}, parent = nil, children = {} diff --git a/modpol/orgs/requests.lua b/modpol/orgs/requests.lua index 9b405ba..22d0e0b 100644 --- a/modpol/orgs/requests.lua +++ b/modpol/orgs/requests.lua @@ -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)