remove_child_consent.lua 2.1 KB

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