Added modpol.approved and modpol.add_policy functions

This commit is contained in:
Nathan Schneider 2021-02-11 21:59:17 +00:00
parent b6ac30ee72
commit 6a6220b253
2 changed files with 76 additions and 17 deletions

View File

@ -185,10 +185,38 @@ function modpol.remove_member(org, member)
end
-- ===================================================================
-- TKTK:
-- + rename_org(old_name, new_name)
-- +
-- TKTK
-- rename_org(old_name, new_name)
-- Renames an org
-- ===================================================================
-- modpol.add_policy
-- Adds a policy to an org's [org].policies table
-- Params: org_name (string), target_function (string),
-- policy_function (string)
-- function names should be in the form [module?.][function]
-- and can be modpol.delegate(org_name)
-- Output: true if successful, nil if error
modpol.add_policy = function(org_name, target_function, policy_function)
-- first, basic checks
local message = "Error: No such org"
if (modpol.orgs[org_name] == nil) then
return nil, message
elseif (modpol[target_function] == nil) then
message = "Error: No such target function"
return nil, message
elseif (modpol[policy_function]) then
message = "Error: No such policy function"
return nil, message
else
-- okay, proceed
modpol.orgs[org_name].policies[target_function] = policy_function
message = "In org " .. org_name .. ", policy for " .. target_function
.. " set to " .. policy_function
record(org_name, message)
return true, message
end
end
-- ===================================================================
-- End of file.

View File

@ -6,6 +6,31 @@
-- TKTK may need to create high-level modpol.processes table to hold ongoing processes
-- TKTK in order to enable async processes. Rewrite all this as listeners
-- ===================================================================
-- Function: modpol.switchboard
-- Params: org (string), routine (string)
-- Outputs: Checks the org for any policies related to a given function;
-- Calls the modpol.initiate.* function(org) based on policy
-- Defaults to modpol.initiate.consent()
modpol.switchboard = function(org, routine)
if modpol.orgs[org]["policies"]
and modpol.orgs[org]["policies"][routine] then
-- TKTK if there exists a policy, initiate that function
else
modpol.initiate.consent(org)
end
end
-- ===================================================================
-- TKTK
-- Function: modpol.delegate
-- Delegates a process from one org to another
-- ===================================================================
-- Basic decision functions
-- ===================================================================
-- ===================================================================
-- Function: modpol.consent
-- Params: org (string), proposal (string)
@ -30,6 +55,26 @@ modpol.consent = function(org, query)
return true, responses
end
-- ===================================================================
-- Function: modpol.approved
-- A simple function for automatically approved processes
-- Params: none
-- Outputs: boolean - true
modpol.approved = function()
-- Check that org exists
if modpol.orgs[org] == nil then
return nil, "Error: Org does not exist"
end
return true
end
-- ===================================================================
-- Experimental
-- ===================================================================
-- ===================================================================
-- TKTK exploring modpol.initiate functions, which have no args
-- Need to properly document these
modpol.initiate = {}
@ -39,17 +84,3 @@ modpol.initiate.consent = function(org)
local query = io.read()
return modpol.consent(org, query)
end
-- Function: modpol.switchboard
-- Params: org (string), routine (string)
-- Outputs: Checks the org for any policies related to a given function;
-- Calls the modpol.initiate.* function(org) based on policy
-- Defaults to modpol.initiate.consent()
modpol.switchboard = function(org, routine)
if modpol.orgs[org]["policies"]
and modpol.orgs[org]["policies"][routine] then
-- TKTK if there exists a policy
else
modpol.initiate.consent(org)
end
end