defer_consent.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --- defer_consent
  2. -- @module defer_consent
  3. --- (Required): data table containing name and description of the module
  4. -- @field name "Human-readable name (parens OK, no brackets)"
  5. -- @field slug "Same as module class name"
  6. -- @field desc "Description of the module"
  7. -- @field hide "Whether this is a hidden utility module"
  8. local defer_consent = {
  9. name = "Defer consent",
  10. slug = "defer_consent",
  11. desc = "Defers consent on a decision to another org",
  12. hide = true;
  13. }
  14. --- (Required) Data for module
  15. -- Variables that module uses during the course of a process
  16. -- Can be blank
  17. defer_consent.data = {
  18. }
  19. --- (Required): config for module
  20. -- @field defer_org Name or ID of target org
  21. -- @field votes_required Threshold passed on to `consent`
  22. -- @field prompt String passed on to `consent`
  23. defer_consent.config = {
  24. defer_org = "Root",
  25. votes_required = 1,
  26. prompt = "Do you consent?"
  27. }
  28. --- (Required): initiate function
  29. -- @param result (optional) Callback if this module is embedded in other modules
  30. -- @function initiate
  31. function defer_consent:initiate(result)
  32. local defer_org = modpol.orgs.get_org(self.config.defer_org)
  33. if not defer_org then
  34. modpol.interactions.message(
  35. self.initiator, "Target org not found, aborting")
  36. self.org:delete_process(self.id)
  37. else
  38. defer_org:call_module(
  39. "consent", self.initiator,
  40. {
  41. votes_required = self.config.votes_required,
  42. prompt = self.config.prompt
  43. },
  44. function()
  45. if result then result() end
  46. end)
  47. end
  48. if result then result() end
  49. self.org:delete_process(self.id)
  50. end
  51. --- (Required) Add to module table
  52. modpol.modules.defer_consent = defer_consent