Some unfinished, broken additions to processes

This commit is contained in:
Nathan Schneider 2021-02-20 22:48:17 -07:00
parent bf309aa63d
commit 4f53e801c4
2 changed files with 52 additions and 22 deletions

View File

@ -189,15 +189,25 @@ end
-- rename_org(old_name, new_name) -- rename_org(old_name, new_name)
-- Renames an org -- 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 -- modpol.add_policy
-- Adds a policy to an org's [org].policies table -- Adds a policy to an org's [org].policies table
-- Params: org_name (string), target_function (string), -- Params: org_name (string),
-- policy_function (string) -- policy_name (string),
-- function names should be in the form [module?.][function] -- policy_table (table)
-- and can be modpol.delegate(org_name)
-- Output: true if successful, nil if error -- 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 -- first, basic checks
local message = "Error: No such org" local message = "Error: No such org"
if (modpol.orgs[org_name] == nil) then if (modpol.orgs[org_name] == nil) then

View File

@ -3,28 +3,50 @@
-- Process-related functions for Modular Politics -- Process-related functions for Modular Politics
-- Called by modpol.lua -- 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 -- Function: modpol.register_process
-- Params: org (string), routine (string) -- Adds a process to modpol.processes
-- Outputs: Checks the org for any policies related to a given function;
-- ===================================================================
-- 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 -- Calls the modpol.initiate.* function(org) based on policy
-- Defaults to modpol.initiate.consent() -- Defaults to modpol.initiate.consent()
modpol.switchboard = function(org, routine) modpol.begin_process = function(user, org, action)
if modpol.orgs[org]["policies"] if modpol.orgs[org]["policies"]
and modpol.orgs[org]["policies"][routine] then and modpol.orgs[org]["policies"][routine] then
-- TKTK if there exists a policy, initiate that function -- check user org membership is satisfied
else -- register process
modpol.initiate.consent(org) -- start the appropriate process
end else
-- register process (or does .initiate.* do that?)
modpol.initiate.consent(org)
end
end end
-- =================================================================== -- ===================================================================
-- TKTK -- Function: modpol.update_process
-- Function: modpol.delegate
-- Delegates a process from one org to another -- ===================================================================
-- Function: modpol.end_process
-- =================================================================== -- ===================================================================
@ -68,8 +90,6 @@ modpol.approved = function()
return true return true
end end
-- =================================================================== -- ===================================================================
-- Experimental -- Experimental
-- =================================================================== -- ===================================================================