rename_org_consent.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. --- Rename org (consent)
  2. -- A simple module that calls a consent process on an org to rename it.
  3. -- Depends on the Consent module.
  4. local rename_org_consent = {
  5. name = "Rename this org (consent)",
  6. slug = "rename_org_consent",
  7. desc = "Renames an org if all members consent."
  8. }
  9. rename_org_consent.data = {
  10. result = nil,
  11. new_name = nil
  12. }
  13. rename_org_consent.config = {
  14. }
  15. function rename_org_consent:initiate(result)
  16. modpol.interactions.text_query(
  17. self.initiator,"New org name: ",
  18. function(input)
  19. if input == "" then
  20. modpol.interactions.message(
  21. self.initiator,
  22. "No name entered for child org")
  23. modpol.interactions.org_dashboard(
  24. self.initiator, self.org.name)
  25. self.org:delete_process(self.id)
  26. if result then result() end
  27. return
  28. elseif modpol.orgs.get_org(input) then
  29. modpol.interactions.message(
  30. self.initiator,
  31. "Org name already in use")
  32. modpol.interactions.org_dashboard(
  33. self.initiator, self.org.name)
  34. self.org:delete_process(self.id)
  35. if result then result() end
  36. return
  37. end
  38. self.data.new_name = input
  39. modpol.interactions.message(
  40. self.initiator,
  41. "Proposed to change name of org " ..
  42. self.org.name .. " to " .. input)
  43. -- initiate consent process
  44. self.org:call_module(
  45. "consent",
  46. self.initiator,
  47. {
  48. prompt = "Change name of org " ..
  49. self.org.name .. " to " .. input .. "?",
  50. votes_required = #self.org.members
  51. },
  52. function()
  53. self:complete()
  54. end
  55. )
  56. modpol.interactions.org_dashboard(
  57. self.initiator, self.org.name)
  58. end
  59. )
  60. end
  61. function rename_org_consent:complete()
  62. modpol.interactions.message_org(
  63. self.initiator,
  64. self.org.name,
  65. "Changing name of org " .. self.org.name ..
  66. " to " .. self.data.new_name)
  67. self.org.name = self.data.new_name
  68. if self.data.result then self.data.result() end
  69. self.org:delete_process(self.id)
  70. end
  71. modpol.modules.rename_org_consent = rename_org_consent