remove_member_consent.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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
  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.org: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. function remove_member_consent:complete()
  51. modpol.interactions.message_org(
  52. self.initiator, self.org.id,
  53. "Consent reached: removing "..
  54. self.data.member_to_remove..
  55. " from org "..self.org.name)
  56. self.org:remove_member(self.data.member_to_remove)
  57. self.org:delete_process(self.id)
  58. if self.data.result then self.data.result() end
  59. end
  60. modpol.modules.remove_member_consent = remove_member_consent