Added basic policy backend for modules. Also added confirmation in CLI to call a module. At that confirmation, the relevant policies are shown. Still need to create a module for changing policies and to add more configuration options to existing policies.
This commit is contained in:
@ -5,6 +5,35 @@
|
||||
|
||||
modpol.interactions = {}
|
||||
|
||||
-- UTILITIES
|
||||
-- =========
|
||||
|
||||
--- Output: returns a string listing a module's policies
|
||||
-- @function modpol.interactions.get_policy_string
|
||||
-- @param org (string or number) name or id for the org
|
||||
-- @param module_slug (string)
|
||||
-- @param sep (string) separator string
|
||||
function modpol.interactions.get_policy_string(
|
||||
org, module_slug, sep)
|
||||
local this_org = modpol.orgs.get_org(org)
|
||||
local this_module = modpol.modules[module_slug]
|
||||
local output = {}
|
||||
if modpol.util.num_pairs(this_module.config) > 0 then
|
||||
for k, v in pairs(this_module.config) do
|
||||
local this_policy = ""
|
||||
-- org policies
|
||||
if this_org.policies[module_slug]
|
||||
and this_org.policies[module_slug][k] then
|
||||
this_policy = k .. " - " ..
|
||||
tostring(this_org.policies[module_slug][k])
|
||||
else
|
||||
this_policy = k .. " - " .. tostring(v)
|
||||
end
|
||||
table.insert(output,this_policy)
|
||||
end
|
||||
end
|
||||
return "Policies:\n" .. table.concat(output, sep)
|
||||
end
|
||||
|
||||
-- DASHBOARDS
|
||||
-- ==========
|
||||
@ -165,8 +194,23 @@ function modpol.interactions.org_dashboard(user, org_string)
|
||||
module_result = true
|
||||
end
|
||||
end
|
||||
local module = org.modules[module_sel]
|
||||
if module_result then
|
||||
org:call_module(module_sel, user)
|
||||
modpol.interactions.binary_poll_user(
|
||||
user,
|
||||
module.name..":\n"..
|
||||
module.desc.."\n"..
|
||||
modpol.interactions.get_policy_string(
|
||||
org.name, module.slug, "\n")..
|
||||
"\n".."Proceed?",
|
||||
function(input)
|
||||
if input == "Yes" then
|
||||
org:call_module(module_sel, user)
|
||||
elseif input == "No" then
|
||||
modpol.interactions.org_dashboard(
|
||||
pname, org.id)
|
||||
end
|
||||
end)
|
||||
else
|
||||
print("Error: Module not found.")
|
||||
modpol.interactions.org_dashboard(user, org.id)
|
||||
|
Reference in New Issue
Block a user