consent.lua 1.6 KB

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