display_policies.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 type(v2) == "string" then
  29. v2_string = v2
  30. elseif type(v2) == "table"
  31. or type(v2) == "number" then
  32. v2_string = tostring(v2)
  33. else
  34. v2_string = "Could not render"
  35. end
  36. input = k2..": "..v2_string
  37. table.insert(display_table, input)
  38. end
  39. end
  40. table.insert(display_table, "---")
  41. end
  42. end
  43. local output = table.concat(display_table,"\n")
  44. if #display_table == 0 then
  45. output = "No modules found"
  46. end
  47. modpol.interactions.display(
  48. self.initiator,
  49. "Policies in org "..self.org.name,
  50. output,
  51. function()
  52. modpol.interactions.org_dashboard(
  53. self.initiator, self.org.id)
  54. if result then result() end
  55. self.org:delete_process(self.id)
  56. end
  57. )
  58. end
  59. modpol.modules.display_policies = display_policies