remove_member_consent.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --- Calls consent to remove member from org
  2. -- @module remove_member_consent
  3. local remove_member_consent = {
  4. name = "Remove a member (consent)",
  5. slug = "remove_member_consent",
  6. desc = "Removes org member with consent of other members"
  7. }
  8. remove_member_consent.data = {
  9. member_to_remove = "",
  10. result = nil
  11. }
  12. remove_member_consent.config = {
  13. }
  14. --- Removes given member from org
  15. -- @function remove_member_consent:initiate
  16. -- @param result Callback if this module is embedded in other modules
  17. function remove_member_consent:initiate(result)
  18. -- Abort if in root org
  19. if self.org == modpol.instance then
  20. modpol.interactions.message(
  21. self.initiator,
  22. "Members cannot be removed from the root org")
  23. if result then result() end
  24. self.org:delete_process(self.id)
  25. else -- proceed if not root
  26. self.data.result = result
  27. modpol.interactions.dropdown_query(
  28. self.initiator,
  29. "Which member of org "..self.org.name..
  30. " do you want to remove?",
  31. self.org.members,
  32. function(input)
  33. self.data.member_to_remove = input
  34. self:call_module(
  35. "consent",
  36. self.initiator,
  37. {
  38. prompt = "Remove "..input..
  39. " from org "..self.org.name.."?",
  40. votes_required = #self.org.members - 1
  41. },
  42. function()
  43. self:complete()
  44. end)
  45. modpol.interactions.org_dashboard(
  46. self.initiator, self.org.name)
  47. end)
  48. end
  49. end
  50. --- Complete after consent
  51. -- @function remove_member_consent:complete
  52. function remove_member_consent:complete()
  53. modpol.interactions.message_org(
  54. self.initiator, self.org.id,
  55. "Consent reached: removing "..
  56. self.data.member_to_remove..
  57. " from org "..self.org.name)
  58. self.org:remove_member(self.data.member_to_remove)
  59. self.org:delete_process(self.id)
  60. if self.data.result then self.data.result() end
  61. end
  62. modpol.modules.remove_member_consent = remove_member_consent