remove_org.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --- Remove org
  2. -- Removes the current org
  3. -- @module remove_org
  4. local remove_org = {
  5. name = "Remove this org",
  6. slug = "remove_org",
  7. desc = "Removes this org."
  8. }
  9. remove_org.data = {
  10. result = nil
  11. }
  12. remove_org.config = {
  13. approval_module = false
  14. }
  15. --- Remove org if all members consent
  16. -- @function remove_org:initiate
  17. -- @param result Callback if this module is embedded in other modules
  18. function remove_org:initiate(result)
  19. if self.org == modpol.instance then
  20. modpol.interactions.message(
  21. self.initiator,
  22. "Cannot remove root org")
  23. if result then result() end
  24. self.org:delete_process(self.id)
  25. else
  26. self.data.result = result
  27. self:call_module(
  28. self.config.approval_module,
  29. self.initiator,
  30. {
  31. prompt = "Remove org " .. self.org.name .. "?"
  32. },
  33. function()
  34. self:complete()
  35. end
  36. )
  37. modpol.interactions.org_dashboard(
  38. self.initiator, modpol.orgs.get_org(self.org.parent).name)
  39. end
  40. end
  41. --- Complete after approval
  42. -- @function remove_org:complete
  43. function remove_org:complete()
  44. modpol.interactions.message_org(
  45. self.initiator, self.org.id,
  46. "Removing org " .. self.org.name)
  47. if self.data.result then self.data.result() end
  48. self.org:delete_process(self.id)
  49. self.org:delete()
  50. end
  51. modpol.modules.remove_org = remove_org