Răsfoiți Sursa

drafting consent module

Luke Miller 3 ani în urmă
părinte
comite
68d8da7290
1 a modificat fișierele cu 37 adăugiri și 0 ștergeri
  1. 37 0
      modpol/modules/consent.lua

+ 37 - 0
modpol/modules/consent.lua

@@ -0,0 +1,37 @@
+rough_idea = { -- a lot of these might want to call org functions instead of being hard coded
+    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
+end
+
+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