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:
Nathan Schneider 2022-02-05 23:49:23 -07:00
parent fc8cd20e7f
commit b92272afa2
4 changed files with 70 additions and 13 deletions

View File

@ -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)

View File

@ -15,11 +15,12 @@ function temp_org()
id = nil,
name = nil,
modules = modpol.util.copy_table(modpol.modules),
policies = {},
processes = {},
pending = {},
members = {},
parent = nil,
children = {}
children = {},
}
end

View File

@ -18,12 +18,22 @@ function modpol.orgs:call_module(module_slug, initiator, config, result, parent_
local module = modpol.modules[module_slug]
-- sets default values for undeclared config variables
if modpol.util.num_pairs(module.config) > 0 and config then
for k, v in pairs(module.config) do
if config[k] == nil then
config[k] = v
end
end
-- first applies any relevant org policies
-- then overrides with the config values given on input
local new_config = {}
if modpol.util.num_pairs(module.config) > 0 then
for k, v in pairs(module.config) do
new_config[k] = v
-- org policies
if self.policies[module_slug]
and self.policies[module_slug][k] then
new_config[k] = self.policies[module_slug][k]
end
-- input settings
if config and config[k] then
new_config[k] = config[k]
end
end
end
-- setting default params
@ -34,7 +44,7 @@ function modpol.orgs:call_module(module_slug, initiator, config, result, parent_
id = index,
parent_id = parent_id,
children = {},
config = config,
config = modpol.util.copy_table(new_config),
data = modpol.util.copy_table(module.data),
slug = module_slug
}

View File

@ -237,7 +237,9 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
pname,
module.name..":\n"..
module.desc.."\n"..
"Proceed?",
modpol.interactions.get_policy_string(
org.name, module.slug, ", ")..
"\n".."Proceed?",
function(input)
if input == "Yes" then
org:call_module(module.slug, pname)
@ -570,10 +572,10 @@ function modpol.interactions.binary_poll_user(user, question, func)
-- set up formspec
local formspec = {
"formspec_version[4]",
"size[8,4]",
"size[8,6]",
"label[0.375,0.5;",minetest.formspec_escape(question), "]",
"button[1,2.5;1,0.8;yes;Yes]",
"button[2,2.5;1,0.8;no;No]",
"button[1,5;1,0.8;yes;Yes]",
"button[2,5;1,0.8;no;No]",
--TODO can we enable text wrapping?
--TODO we could use scroll boxes to contain the text
}