From 6a6220b253d159a41e7443327d4c007017798a9b Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Thu, 11 Feb 2021 21:59:17 +0000 Subject: [PATCH] Added modpol.approved and modpol.add_policy functions --- modpol/orgs/orgs.lua | 34 ++++++++++++++++++-- modpol/processes/processes.lua | 59 ++++++++++++++++++++++++++-------- 2 files changed, 76 insertions(+), 17 deletions(-) diff --git a/modpol/orgs/orgs.lua b/modpol/orgs/orgs.lua index c4596ca..0e9f8ac 100644 --- a/modpol/orgs/orgs.lua +++ b/modpol/orgs/orgs.lua @@ -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. diff --git a/modpol/processes/processes.lua b/modpol/processes/processes.lua index 729db67..83d3bfa 100644 --- a/modpol/processes/processes.lua +++ b/modpol/processes/processes.lua @@ -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 \ No newline at end of file