consent.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. rough_idea = { -- a lot of these might want to call org functions instead of being hard coded
  2. type = "consent",
  3. org_id = 5, -- may be needed for defer_to, process sent to a diff org
  4. request_id = 1, -- callback to request
  5. total_votes = 2,
  6. to_pass = 3, -- could default to majority, but could set super majority
  7. eligible_voters = 5,
  8. timeout = 234235325, -- timestamp when vote ends
  9. votes_yes = {
  10. "lukvmil"
  11. },
  12. votes_no = {
  13. "nathan"
  14. }
  15. }
  16. function modules.consent.cast_vote(user, decision, org_id, process_id)
  17. local org = modpol.orgs.get_org(org_id)
  18. local process = org:get_process(process_id)
  19. if decision == "yes" then
  20. table.insert(process.votes_yes, user)
  21. elseif decision == "no" then
  22. table.insert(process.votes_no, user)
  23. else
  24. return false
  25. process.total_votes = process.total_votes + 1
  26. call_vote_check(process) -- some call to determine if the vote has reached an end condition
  27. end
  28. function modules.consent.call_vote_check(process)
  29. if votes_yes > to_pass then
  30. call_success()
  31. elseif votes_no > to_pass then
  32. call_failure()
  33. end
  34. end