display_policies.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --- Display policies
  2. -- @module display_policies
  3. local display_policies = {
  4. name = "Display policies",
  5. slug = "display_policies",
  6. desc = "Presents a detailed list of org policies",
  7. hide = false;
  8. }
  9. display_policies.data = {
  10. }
  11. display_policies.config = {
  12. }
  13. --- Initiate function
  14. -- @function display_policies:initiate
  15. -- @param result Callback if this module is embedded in other modules
  16. function display_policies:initiate(result)
  17. local display_table = {}
  18. for k,v in pairs(self.org.policies) do
  19. if v then -- check the module is allowed
  20. local input = modpol.modules[k].name
  21. table.insert(display_table, input)
  22. if modpol.modules[k].config then
  23. for k2,v2 in pairs(modpol.modules[k].config) do
  24. if self.org.policies[k][k2] then
  25. v2 = self.org.policies[k][k2]
  26. end
  27. local v2_string = ""
  28. if not v2 then
  29. v2_string = "none"
  30. elseif type(v2) == "string" then
  31. v2_string = v2
  32. elseif type(v2) == "table"
  33. or type(v2) == "number" then
  34. v2_string = tostring(v2)
  35. elseif type(v2) == "boolean" then
  36. v2_string = tostring(v2)
  37. else
  38. v2_string = "Could not render"
  39. end
  40. input = k2..": "..v2_string
  41. table.insert(display_table, input)
  42. end
  43. end
  44. table.insert(display_table, "---")
  45. end
  46. end
  47. local output = table.concat(display_table,"\n")
  48. if #display_table == 0 then
  49. output = "No modules found"
  50. end
  51. modpol.interactions.display(
  52. self.initiator,
  53. "Policies in org "..self.org.name,
  54. output,
  55. function()
  56. self.org:delete_process(self.id)
  57. modpol.interactions.org_dashboard(
  58. self.initiator, self.org.id)
  59. if result then result() end
  60. end
  61. )
  62. end
  63. modpol.modules.display_policies = display_policies