remove_member.lua 2.0 KB

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