remove_org_consent.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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
  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.org: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. function remove_org_consent:complete()
  43. modpol.interactions.message_org(
  44. self.initiator, self.org.id,
  45. "Consent reached: removing org " .. self.org.name)
  46. if self.data.result then self.data.result() end
  47. self.org:delete_process(self.id)
  48. self.org:delete()
  49. end
  50. modpol.modules.remove_org_consent = remove_org_consent