consent.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. modpol.modules.consent = {
  2. type = "consent",
  3. }
  4. -- sets consent to its own callback
  5. modpol.modules.consent.__index = modpol.modules.consent
  6. function temp_consent_process()
  7. return {
  8. org_id = nil,
  9. request_id = nil,
  10. total_votes = nil,
  11. votes_yes = {},
  12. votes_no = {}
  13. }
  14. end
  15. -- ===============================================
  16. -- function to create a new consent process to resolve a pending process
  17. function modpol.modules.consent.new_process(request_id, org_id)
  18. local process = temp_consent_process()
  19. process.request_id = request_id
  20. process.org_id = org_id
  21. setmetatable(process, modpol.modules.consent)
  22. modpol.ocutil.log('Created new process for request id')
  23. return temp_consent_process
  24. end
  25. -- ======================================================
  26. -- function for users to vote on a pending request
  27. function modpol.modules.consent:approve(user, decision)
  28. if decision then
  29. table.insert(self.votes_yes, user)
  30. modpol.ocutil.log('User ' .. user .. ' voted yes on request #' .. self.request_id)
  31. else
  32. table.insert(self.votes_no, user)
  33. modpol.ocutil.log('User ' .. user .. ' voted no on request #' .. self.request_id)
  34. self.total_votes = self.total_votes + 1
  35. end
  36. -- ===================================================
  37. -- determines whether process has finished and resolves request if it has (unfinished)
  38. function modules.consent.call_vote_check(process)
  39. if votes_yes > to_pass then
  40. call_success()
  41. elseif votes_no > to_pass then
  42. call_failure()
  43. end
  44. end