rename_org_consent.lua 2.5 KB

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