remove_child_consent.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --- Remove child (consent)
  2. -- A simple module that calls a consent process on an org to remove its child
  3. -- Depends on the Consent module.
  4. -- @module remove_child_consent
  5. local remove_child_consent = {
  6. name = "Remove child (consent)",
  7. slug = "remove_child_consent",
  8. desc = "Removes a child org if all members of this org consent."
  9. }
  10. remove_child_consent.data = {
  11. result = nil,
  12. child_to_remove = nil
  13. }
  14. remove_child_consent.config = {
  15. }
  16. --- Removes a child org with consent
  17. -- @function remove_child_consent:initiate
  18. -- @param result
  19. function remove_child_consent:initiate(result)
  20. local children = {}
  21. for i,v in ipairs(self.org.children) do
  22. local child = modpol.orgs.get_org(v)
  23. if child then table.insert(children, child.name) end
  24. end
  25. -- Abort if no child orgs
  26. if #children == 0 then
  27. modpol.interactions.message(
  28. self.initiator,
  29. "Org has no children")
  30. if result then result() end
  31. self.org:delete_process(self.id)
  32. else
  33. self.data.result = result
  34. modpol.interactions.dropdown_query(
  35. self.initiator,
  36. "Choose a child of org "..
  37. self.org.name.." to remove:",
  38. children,
  39. function(input)
  40. self.data.child_to_remove = modpol.orgs.get_org(input)
  41. self.org:call_module(
  42. "consent",
  43. self.initiator,
  44. {
  45. prompt = "Remove child org "..input.."?",
  46. votes_required = #self.org.members
  47. },
  48. function()
  49. self:complete()
  50. end)
  51. modpol.interactions.org_dashboard(
  52. self.initiator, self.org.name)
  53. end)
  54. end
  55. end
  56. function remove_child_consent:complete()
  57. modpol.interactions.message_org(
  58. self.initiator, self.data.child_to_remove.id,
  59. "Removing org " .. self.data.child_to_remove.name ..
  60. " by parent org consent")
  61. modpol.interactions.message_org(
  62. self.initiator, self.org.id,
  63. "Consent reached: removing org " ..
  64. self.data.child_to_remove.name)
  65. self.data.child_to_remove:delete()
  66. if self.data.result then self.data.result() end
  67. self.org:delete_process(self.id)
  68. end
  69. modpol.modules.remove_child_consent = remove_child_consent