remove_org_consent.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --- Remove org (consent)
  2. -- A simple module that calls a consent process on an org to remove it.
  3. -- Depends on the Consent module.
  4. -- @module remove_org_consent
  5. local remove_org_consent = {
  6. name = "Remove this org (consent)",
  7. slug = "remove_org_consent",
  8. desc = "Removes an org if all members consent."
  9. }
  10. remove_org_consent.data = {
  11. result = nil
  12. }
  13. remove_org_consent.config = {
  14. }
  15. --- Remove org if all members consent
  16. -- @function remove_org_consent:initiate
  17. -- @param result Callback if this module is embedded in other modules
  18. function remove_org_consent: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. "consent",
  29. self.initiator,
  30. {
  31. prompt = "Remove org " .. self.org.name .. "?",
  32. votes_required = #self.org.members
  33. },
  34. function()
  35. self:complete()
  36. end
  37. )
  38. modpol.interactions.org_dashboard(
  39. self.initiator, self.org.name)
  40. end
  41. end
  42. --- Complete after consent
  43. -- @function remove_org_consent:complete
  44. function remove_org_consent:complete()
  45. modpol.interactions.message_org(
  46. self.initiator, self.org.id,
  47. "Consent reached: removing org " .. self.org.name)
  48. if self.data.result then self.data.result() end
  49. self.org:delete_process(self.id)
  50. self.org:delete()
  51. end
  52. modpol.modules.remove_org_consent = remove_org_consent