add_child_org.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --- @module add_child_org
  2. -- Adds a child org
  3. -- Depends on `consent`
  4. local add_child_org = {
  5. name = "Add child org",
  6. slug = "add_child_org",
  7. desc = "Create a child org within the current one with consent"
  8. }
  9. add_child_org.data = {
  10. child_name = ""
  11. }
  12. add_child_org.config = {
  13. }
  14. -- @function initiate
  15. function add_child_org:initiate(config, result)
  16. modpol.interactions.text_query(
  17. self.initiator,"Child org name: ",
  18. function(input)
  19. if input == "" then
  20. modpol.interactions.message(
  21. self.initiator,
  22. "No name entered for child org")
  23. self.org:delete_process(self.id)
  24. return end
  25. self.data.child_name = input
  26. modpol.interactions.message(
  27. self.initiator,
  28. "Proposed child org: " .. input)
  29. -- initiate consent process
  30. self.org:call_module(
  31. "consent",
  32. self.initiator,
  33. {
  34. prompt = "Create child org " ..
  35. self.data.child_name .. "?",
  36. votes_required = #self.org.members
  37. },
  38. function()
  39. self:create_child_org()
  40. end
  41. )
  42. modpol.interactions.org_dashboard(
  43. self.initiator, self.org.name)
  44. end
  45. )
  46. end
  47. function add_child_org:create_child_org()
  48. self.org:add_org(self.data.child_name, self.initiator)
  49. modpol.interactions.message_org(
  50. self.initiator,
  51. self.org.name,
  52. "Child org created: "..self.data.child_name)
  53. self.org:delete_process(self.id)
  54. end
  55. --- (Required) Add to module table
  56. modpol.modules.add_child_org = add_child_org