defer_consent.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --- Defer consent
  2. -- @module defer_consent
  3. local defer_consent = {
  4. name = "Defer consent",
  5. slug = "defer_consent",
  6. desc = "Defers consent on a decision to another org",
  7. hide = true;
  8. }
  9. defer_consent.data = {
  10. }
  11. --- Config for module
  12. -- @field defer_org Name or ID of target org
  13. -- @field votes_required Threshold passed on to `consent`
  14. -- @field prompt String passed on to `consent`
  15. defer_consent.config = {
  16. defer_org = "Root",
  17. votes_required = 1,
  18. prompt = "Do you consent?"
  19. }
  20. --- Initiate function
  21. -- @param result Callback if this module is embedded in other modules
  22. -- @function defer_consent:initiate
  23. function defer_consent:initiate(result)
  24. local defer_org = modpol.orgs.get_org(self.config.defer_org)
  25. if not defer_org then
  26. modpol.interactions.message(
  27. self.initiator, "Target org not found, aborting")
  28. self.org:delete_process(self.id)
  29. else
  30. defer_org:call_module(
  31. "consent", self.initiator,
  32. {
  33. votes_required = self.config.votes_required,
  34. prompt = self.config.prompt
  35. },
  36. function()
  37. if result then result() end
  38. end)
  39. end
  40. if result then result() end
  41. self.org:delete_process(self.id)
  42. end
  43. --- (Required) Add to module table
  44. modpol.modules.defer_consent = defer_consent