defer.lua 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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, self.initiator,
  32. {
  33. prompt = self.config.prompt
  34. },
  35. function()
  36. if result then result() end
  37. end)
  38. end
  39. if result then result() end
  40. self.org:delete_process(self.id)
  41. end
  42. --- (Required) Add to module table
  43. modpol.modules.defer = defer