Browse Source

Created display_policies module to show existing module.config data across an org

Nathan Schneider 2 years ago
parent
commit
9d4ad377e6
2 changed files with 64 additions and 0 deletions
  1. 1 0
      modpol_core/api.lua
  2. 63 0
      modpol_core/modules/display_policies.lua

+ 1 - 0
modpol_core/api.lua

@@ -18,6 +18,7 @@ dofile (localdir .. "/modules/change_modules.lua")
 dofile (localdir .. "/modules/consent.lua")
 dofile (localdir .. "/modules/create_token.lua")
 dofile (localdir .. "/modules/defer_consent.lua")
+dofile (localdir .. "/modules/display_policies.lua")
 dofile (localdir .. "/modules/display_processes.lua")
 dofile (localdir .. "/modules/join_org_consent.lua")
 dofile (localdir .. "/modules/leave_org.lua")

+ 63 - 0
modpol_core/modules/display_policies.lua

@@ -0,0 +1,63 @@
+--- Display policies
+-- @module display_policies
+
+local display_policies = {
+    name = "Display policies",
+    slug = "display_policies",
+    desc = "Presents a detailed list of org policies",
+    hide = false;
+}
+
+display_policies.data = {
+}
+
+display_policies.config = {
+}
+
+--- Initiate function
+-- @function display_policies:initiate
+-- @param result Callback if this module is embedded in other modules
+function display_policies:initiate(result)
+   local display_table = {}
+   for k,v in pairs(self.org.modules) do
+      if v ~= "deleted" then
+         local input = v.name
+         table.insert(display_table, input)
+         if v.config
+            and modpol.util.num_pairs(v.config) > 0 then
+            table.insert(display_table, "Policies:")
+            for k2,v2 in pairs(v.config) do
+               local v2_string = ""
+               if type(v2) ~= "string"
+                  and type(v2) ~= "table" then
+                  v2_string = tostring(v2)
+               elseif type(v2) == "table" then
+                  v2_string = tostring(v2)
+               else
+                  v2_string = "Could not render"
+               end
+               input = k2..": "..v2_string
+               table.insert(display_table, input)
+            end
+         end
+         table.insert(display_table, "\n")
+      end
+   end
+   local output = table.concat(display_table,"\n")
+   if #display_table == 0 then
+      output = "No modules found"
+   end
+   modpol.interactions.display(
+      self.initiator,
+      "Policies in org "..self.org.name,
+      output,
+      function()
+         modpol.interactions.org_dashboard(
+            self.initiator, self.org.id)
+         if result then result() end
+         self.org:delete_process(self.id)
+      end
+   )
+end
+
+modpol.modules.display_policies = display_policies