adding to org dashboard, added check to make sure user is actually able to interact with process, set votes needed at process creation to prevent a stalemate if a user joins after

This commit is contained in:
Luke Miller
2021-08-16 16:25:42 -04:00
parent a6963ed84f
commit 76db1ea87f
3 changed files with 90 additions and 33 deletions

View File

@@ -13,6 +13,7 @@ function temp_consent_process()
request_id = nil,
total_votes = 0,
majority_to_pass = 0.51,
votes_needed = nil,
votes_yes = {},
votes_no = {}
}
@@ -35,6 +36,8 @@ function modpol.modules.consent:new_process(id, request_id, org_id)
p_org:add_pending_action(id, member)
end
process.votes_needed = math.ceil(process.majority_to_pass * p_org:get_member_count())
return process
end
@@ -82,13 +85,11 @@ end
-- determines whether process has finished and resolves request if it has (unfinished)
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
if #self.votes_yes >= self.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
elseif #self.votes_no >= self.votes_needed then
modpol.ocutil.log('Request #' .. self.request_id .. ' fails to pass')
process_org:resolve_request(self.request_id, false)
else