From 4f53e801c4290427d66774f42cd3c9a7e17da345 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Sat, 20 Feb 2021 22:48:17 -0700 Subject: [PATCH] Some unfinished, broken additions to processes --- modpol/orgs/orgs.lua | 20 +++++++++---- modpol/processes/processes.lua | 54 +++++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/modpol/orgs/orgs.lua b/modpol/orgs/orgs.lua index 0e9f8ac..871edc4 100644 --- a/modpol/orgs/orgs.lua +++ b/modpol/orgs/orgs.lua @@ -189,15 +189,25 @@ end -- rename_org(old_name, new_name) -- Renames an org +-- =================================================================== +-- POLICIES +-- Each policy is a table with a string for a key. Contents: +-- KEY - name of the policy (string) +-- [member orgs]: external orgs allowed to call policy +-- [function]: the function that initiates the policy +-- =================================================================== + -- =================================================================== -- 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) +-- Params: org_name (string), +-- policy_name (string), +-- policy_table (table) -- Output: true if successful, nil if error -modpol.add_policy = function(org_name, target_function, policy_function) + +-- TKTK NEEDS TO BE REWRITTEN + +modpol.add_policy = function(org_name, policy_name, policy_table) -- first, basic checks local message = "Error: No such org" if (modpol.orgs[org_name] == nil) then diff --git a/modpol/processes/processes.lua b/modpol/processes/processes.lua index 83d3bfa..8a6c699 100644 --- a/modpol/processes/processes.lua +++ b/modpol/processes/processes.lua @@ -3,28 +3,50 @@ -- Process-related functions for Modular Politics -- Called by modpol.lua --- 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 +-- =================================================================== +-- modpol.processes, a high-level table of active processes +-- Process table structure: +-- [name]: unique name +-- [org]: org +-- [update_functions]: table of available update functions +-- [state]: table of relevant data on the state of the function + +modpol.processes = {} -- =================================================================== --- Function: modpol.switchboard --- Params: org (string), routine (string) --- Outputs: Checks the org for any policies related to a given function; +-- Function: modpol.register_process +-- Adds a process to modpol.processes + +-- =================================================================== +-- Function: modpol.delegate_process +-- Delegates a process from one org to another + +-- =================================================================== +-- Function: modpol.begin_process +-- Params: user (string), org (string), action (string) +-- Outputs: Checks the org for any policies related to a given action; -- 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 +modpol.begin_process = function(user, org, action) + if modpol.orgs[org]["policies"] + and modpol.orgs[org]["policies"][routine] then + -- check user org membership is satisfied + -- register process + -- start the appropriate process + else + -- register process (or does .initiate.* do that?) + modpol.initiate.consent(org) + end end -- =================================================================== --- TKTK --- Function: modpol.delegate --- Delegates a process from one org to another +-- Function: modpol.update_process + +-- =================================================================== +-- Function: modpol.end_process + + + -- =================================================================== @@ -68,8 +90,6 @@ modpol.approved = function() return true end - - -- =================================================================== -- Experimental -- ===================================================================