display_policies.lua 1.9 KB

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