2
0

defer.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --- Defer
  2. -- @module defer
  3. local defer = {
  4. name = "Defer ",
  5. slug = "defer",
  6. desc = "Defers a decision to another org",
  7. hide = true;
  8. }
  9. defer.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.config = {
  16. approval_module = "consent",
  17. defer_org = "Root",
  18. prompt = ""
  19. }
  20. --- Initiate function
  21. -- @param result Callback if this module is embedded in other modules
  22. -- @function defer:initiate
  23. function defer: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. self.config.approval_module,
  32. self.initiator,
  33. {
  34. prompt = self.config.prompt
  35. },
  36. function()
  37. if result then result() end
  38. end)
  39. end
  40. modpol.interactions.org_dashboard(
  41. self.initiator, self.org.id)
  42. if result then result() end
  43. self.org:delete_process(self.id)
  44. end
  45. --- (Required) Add to module table
  46. modpol.modules.defer = defer