From fb0bb4f04948747c9e3711f486a0062b9481017d Mon Sep 17 00:00:00 2001 From: Luke Miller Date: Thu, 6 May 2021 00:36:30 -0400 Subject: [PATCH] starting to bring consent module online --- modpol/modules/consent.lua | 70 ++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/modpol/modules/consent.lua b/modpol/modules/consent.lua index bfbad19..9a6b060 100644 --- a/modpol/modules/consent.lua +++ b/modpol/modules/consent.lua @@ -1,37 +1,55 @@ -rough_idea = { -- a lot of these might want to call org functions instead of being hard coded +modpol.modules.consent = { type = "consent", - org_id = 5, -- may be needed for defer_to, process sent to a diff org - request_id = 1, -- callback to request - total_votes = 2, - to_pass = 3, -- could default to majority, but could set super majority - eligible_voters = 5, - timeout = 234235325, -- timestamp when vote ends - votes_yes = { - "lukvmil" - }, - votes_no = { - "nathan" - } } -function modules.consent.cast_vote(user, decision, org_id, process_id) - local org = modpol.orgs.get_org(org_id) - local process = org:get_process(process_id) - if decision == "yes" then - table.insert(process.votes_yes, user) - elseif decision == "no" then - table.insert(process.votes_no, user) - else - return false - - process.total_votes = process.total_votes + 1 - call_vote_check(process) -- some call to determine if the vote has reached an end condition +-- sets consent to its own callback +modpol.modules.consent.__index = modpol.modules.consent + +function temp_consent_process() + return { + org_id = nil, + request_id = nil, + total_votes = nil, + votes_yes = {}, + votes_no = {} + } end +-- =============================================== +-- function to create a new consent process to resolve a pending process +function modpol.modules.consent.new_process(request_id, org_id) + local process = temp_consent_process() + process.request_id = request_id + process.org_id = org_id + + setmetatable(process, modpol.modules.consent) + + modpol.ocutil.log('Created new process for request id') + + return temp_consent_process +end + +-- ====================================================== +-- function for users to vote on a pending request +function modpol.modules.consent:approve(user, decision) + if decision then + table.insert(self.votes_yes, user) + modpol.ocutil.log('User ' .. user .. ' voted yes on request #' .. self.request_id) + else + table.insert(self.votes_no, user) + modpol.ocutil.log('User ' .. user .. ' voted no on request #' .. self.request_id) + + self.total_votes = self.total_votes + 1 + +end + +-- =================================================== +-- determines whether process has finished and resolves request if it has (unfinished) function modules.consent.call_vote_check(process) if votes_yes > to_pass then call_success() elseif votes_no > to_pass then call_failure() end -end \ No newline at end of file +end +