remove_child_consent.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 Callback if this module is embedded in other modules
  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: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. --- Complete the remove process
  57. -- @function remove_child_consent:complete
  58. function remove_child_consent:complete()
  59. modpol.interactions.message_org(
  60. self.initiator, self.data.child_to_remove.id,
  61. "Removing org " .. self.data.child_to_remove.name ..
  62. " by parent org consent")
  63. modpol.interactions.message_org(
  64. self.initiator, self.org.id,
  65. "Consent reached: removing org " ..
  66. self.data.child_to_remove.name)
  67. self.data.child_to_remove:delete()
  68. if self.data.result then self.data.result() end
  69. self.org:delete_process(self.id)
  70. end
  71. modpol.modules.remove_child_consent = remove_child_consent