significant progress! a working process from beginning to end can be seen in test/org_req_test.lua

This commit is contained in:
Luke Miller
2021-05-06 14:13:02 -04:00
parent a7ba7605d3
commit 797d0bebb8
5 changed files with 66 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ function temp_consent_process()
org_id = nil,
request_id = nil,
total_votes = 0,
majority_to_pass = 0.51,
votes_yes = {},
votes_no = {}
}
@@ -33,6 +34,11 @@ end
-- ======================================================
-- function for users to vote on a pending request
function modpol.modules.consent:approve(user, decision)
if not modpol.orgs.get_org(self.org_id):has_member(user) then
modpol.ocutil.log('Error in consent:approve -> user not a member of the org')
return
end
if decision then
table.insert(self.votes_yes, user)
modpol.ocutil.log('User ' .. user .. ' voted yes on request #' .. self.request_id)
@@ -43,15 +49,24 @@ function modpol.modules.consent:approve(user, decision)
self.total_votes = self.total_votes + 1
self:update_status()
end
-- ===================================================
-- determines whether process has finished and resolves request if it has (unfinished)
-- function modpol.modules.consent.call_vote_check(process)
-- if votes_yes > to_pass then
-- call_success()
-- elseif votes_no > to_pass then
-- call_failure()
-- end
-- end
function modpol.modules.consent:update_status()
local process_org = modpol.orgs.get_org(self.org_id)
local eligible_voters = process_org:get_member_count()
local votes_needed = math.ceil(self.majority_to_pass * eligible_voters)
if #self.votes_yes >= votes_needed then
modpol.ocutil.log('Request #' .. self.request_id .. ' passes')
process_org:resolve_request(self.request_id, true)
elseif #self.votes_no >= votes_needed then
modpol.ocutil.log('Request #' .. self.request_id .. ' fails to pass')
process_org:resolve_request(self.request_id, false)
else
modpol.ocutil.log('Waiting for more votes...')
end
end