A bunch of cleaning up of unused files
This commit is contained in:
parent
c2852b1bce
commit
a03528d8fe
@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
local localdir = modpol.topdir
|
local localdir = modpol.topdir
|
||||||
|
|
||||||
--Users
|
|
||||||
dofile (localdir .. "/users/users.lua")
|
|
||||||
|
|
||||||
--orgs
|
--orgs
|
||||||
dofile (localdir .. "/orgs/base.lua")
|
dofile (localdir .. "/orgs/base.lua")
|
||||||
dofile (localdir .. "/orgs/process.lua")
|
dofile (localdir .. "/orgs/process.lua")
|
||||||
|
@ -20,7 +20,7 @@ function modpol.interactions.dashboard(user)
|
|||||||
modpol.instance:add_member(user)
|
modpol.instance:add_member(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
local all_users = modpol.list_users()
|
local all_users = modpol.instance:list_members()
|
||||||
|
|
||||||
print('All orgs: (user orgs indicated by *)')
|
print('All orgs: (user orgs indicated by *)')
|
||||||
for id, org in ipairs(modpol.orgs.array) do
|
for id, org in ipairs(modpol.orgs.array) do
|
||||||
|
@ -1,98 +0,0 @@
|
|||||||
-- TODO: NEEDS TO BE REWRITTEN AS A LIBRARY NOT A MODULE
|
|
||||||
|
|
||||||
modpol.orgs.consent = {}
|
|
||||||
|
|
||||||
-- sets consent to its own callback
|
|
||||||
modpol.orgs.consent.__index = modpol.orgs.consent
|
|
||||||
|
|
||||||
function temp_consent_process()
|
|
||||||
return {
|
|
||||||
type = "consent",
|
|
||||||
id = nil,
|
|
||||||
org_id = nil,
|
|
||||||
request_id = nil,
|
|
||||||
total_votes = 0,
|
|
||||||
majority_to_pass = 0.51,
|
|
||||||
votes_needed = nil,
|
|
||||||
votes_yes = {},
|
|
||||||
votes_no = {}
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ===============================================
|
|
||||||
-- function to create a new consent process to resolve a pending process
|
|
||||||
function modpol.orgs.consent:new_process(id, request_id, org_id)
|
|
||||||
local process = temp_consent_process()
|
|
||||||
process.id = id
|
|
||||||
process.request_id = request_id
|
|
||||||
process.org_id = org_id
|
|
||||||
|
|
||||||
setmetatable(process, modpol.orgs.consent)
|
|
||||||
modpol.ocutil.log('Created new process #' .. id .. ' for request id #' .. request_id)
|
|
||||||
|
|
||||||
local p_org = modpol.orgs.get_org(org_id)
|
|
||||||
|
|
||||||
for i, member in ipairs(p_org.members) do
|
|
||||||
p_org:add_pending_action(id, member)
|
|
||||||
end
|
|
||||||
|
|
||||||
process.votes_needed = math.ceil(process.majority_to_pass * p_org:get_member_count())
|
|
||||||
|
|
||||||
return process
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ============================
|
|
||||||
-- interact function for the consent module
|
|
||||||
-- input: user (string)
|
|
||||||
function modpol.orgs.consent:interact(user)
|
|
||||||
-- TODO this needs more context on the vote at hand
|
|
||||||
modpol.interactions.binary_poll_user(
|
|
||||||
user, "Do you consent?",
|
|
||||||
function(vote)
|
|
||||||
if vote == 'Yes' then
|
|
||||||
self:approve(user, true)
|
|
||||||
elseif vote == 'No' then
|
|
||||||
self:approve(user, false)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ======================================================
|
|
||||||
-- function for users to vote on a pending request
|
|
||||||
function modpol.orgs.consent:approve(user, decision)
|
|
||||||
if not modpol.orgs.get_org(self.org_id):has_member(user) then
|
|
||||||
modpol.ocutil.log('Error in consent:approve -> user not a member of the org')
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if decision then
|
|
||||||
table.insert(self.votes_yes, user)
|
|
||||||
modpol.ocutil.log('User ' .. user .. ' voted yes on request #' .. self.request_id)
|
|
||||||
else
|
|
||||||
table.insert(self.votes_no, user)
|
|
||||||
modpol.ocutil.log('User ' .. user .. ' voted no on request #' .. self.request_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
self.total_votes = self.total_votes + 1
|
|
||||||
|
|
||||||
local p_org = modpol.orgs.get_org(self.org_id)
|
|
||||||
p_org:remove_pending_action(self.id, user)
|
|
||||||
|
|
||||||
self:update_status()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ===================================================
|
|
||||||
-- determines whether process has finished and resolves request if it has (unfinished)
|
|
||||||
function modpol.orgs.consent:update_status()
|
|
||||||
local process_org = modpol.orgs.get_org(self.org_id)
|
|
||||||
|
|
||||||
if #self.votes_yes >= self.votes_needed then
|
|
||||||
modpol.ocutil.log('Request #' .. self.request_id .. ' passes')
|
|
||||||
process_org:resolve_request(self.request_id, true)
|
|
||||||
elseif #self.votes_no >= self.votes_needed then
|
|
||||||
modpol.ocutil.log('Request #' .. self.request_id .. ' fails to pass')
|
|
||||||
process_org:resolve_request(self.request_id, false)
|
|
||||||
else
|
|
||||||
modpol.ocutil.log('Waiting for more votes...')
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,48 +0,0 @@
|
|||||||
--[[
|
|
||||||
modpol calls this function when someone starts a new request for this module
|
|
||||||
--]]
|
|
||||||
|
|
||||||
function module:initiate(org) {
|
|
||||||
|
|
||||||
form = {
|
|
||||||
{
|
|
||||||
"name": "to_remove",
|
|
||||||
"display": "Which user should be removed?",
|
|
||||||
"type": "drop-down",
|
|
||||||
"values": org:list_members()
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "reason",
|
|
||||||
"type": "text-box",
|
|
||||||
"prompt": "Reason for removing member:"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return form
|
|
||||||
}
|
|
||||||
|
|
||||||
--[[
|
|
||||||
modpol prompts the user with this form, and after receiving the data asynchronously
|
|
||||||
the returned form would look like:
|
|
||||||
|
|
||||||
{
|
|
||||||
"to_remove": luke,
|
|
||||||
"reason": stealing food
|
|
||||||
}
|
|
||||||
|
|
||||||
based on provided "name" fields and the input given by the user
|
|
||||||
now module:request is called
|
|
||||||
--]]
|
|
||||||
|
|
||||||
function module:request(form) {
|
|
||||||
self.data = form
|
|
||||||
}
|
|
||||||
|
|
||||||
--[[
|
|
||||||
after the module request function runs, modpol will initiate the consent process
|
|
||||||
if consent is approved, the implement function is called
|
|
||||||
--]]
|
|
||||||
|
|
||||||
function module:implement() {
|
|
||||||
org:remove_member(self.data.to_remove)
|
|
||||||
}
|
|
@ -1,153 +0,0 @@
|
|||||||
old_request_format = {
|
|
||||||
user=user, -- requesting user
|
|
||||||
type="add_member", -- action
|
|
||||||
params={user} -- action params
|
|
||||||
}
|
|
||||||
|
|
||||||
old_process_format = {
|
|
||||||
type = "consent", -- delete
|
|
||||||
id = nil,
|
|
||||||
org_id = nil,
|
|
||||||
request_id = nil, -- delete
|
|
||||||
|
|
||||||
-- consent config
|
|
||||||
majority_to_pass = 0.51, -- voting threshold
|
|
||||||
votes_needed = nil,
|
|
||||||
|
|
||||||
-- consent data
|
|
||||||
total_votes = 0,
|
|
||||||
votes_yes = {},
|
|
||||||
votes_no = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
new_process_format = {
|
|
||||||
initiator = "user",
|
|
||||||
status = "request",
|
|
||||||
org_id = 12314,
|
|
||||||
module = "create_child_org", -- policy table lookup
|
|
||||||
process_id = 8347,
|
|
||||||
timestamp = 1632850133, -- look into supporting other formats, overrides (turn based, etc.)
|
|
||||||
|
|
||||||
data = {
|
|
||||||
child_org_name = "oligarchy"
|
|
||||||
},
|
|
||||||
|
|
||||||
consent = {
|
|
||||||
-- voter eligibilty frozen by action table invites
|
|
||||||
start_time = 384179234,
|
|
||||||
member_count = 14,
|
|
||||||
votes_yes = {},
|
|
||||||
votes_no = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
-- initialize values
|
|
||||||
function init_consent(policy) {
|
|
||||||
self.start_time = os.time()
|
|
||||||
self.member_count = modpol.orgs.get_org(self.org_id):get_member_count()
|
|
||||||
|
|
||||||
if policy.duration then
|
|
||||||
-- mintest.after(time, func, ...args)
|
|
||||||
-- should override modpol callback function
|
|
||||||
register_callback(self.start_time + policy.duration)
|
|
||||||
end
|
|
||||||
|
|
||||||
if (duration and (consent_ratio or yes_threshold or no_threshold)) or (yes_threshold) or (consent_ratio) then
|
|
||||||
-- well formed policy
|
|
||||||
else
|
|
||||||
-- invalid
|
|
||||||
end
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
-- update vote count
|
|
||||||
function update_consent(user, approve) {
|
|
||||||
if approve then
|
|
||||||
table.insert(yes_votes, user)
|
|
||||||
else
|
|
||||||
table.insert(no_votes, user)
|
|
||||||
|
|
||||||
if not duration then
|
|
||||||
eval_consent()
|
|
||||||
end
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
-- evaluate state of vote
|
|
||||||
function eval_consent() {
|
|
||||||
consent_ratio = #yes_votes / (#yes_votes + #no_votes)
|
|
||||||
quorum = (#yes_votes + #no_votes) / member_count
|
|
||||||
|
|
||||||
if policy.duration then
|
|
||||||
|
|
||||||
if policy.consent_ratio then
|
|
||||||
if policy.quorum then
|
|
||||||
if quorum < policy.quorum then
|
|
||||||
fail()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if consent_ratio >= policy.consent_ratio then
|
|
||||||
pass()
|
|
||||||
else
|
|
||||||
fail()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif policy.yes_threshold then
|
|
||||||
if #yes_votes >= policy.yes_threshold then
|
|
||||||
pass()
|
|
||||||
else
|
|
||||||
fail()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif policy.no_threshold then
|
|
||||||
if #no_votes <= policy.no_threshold then
|
|
||||||
fail()
|
|
||||||
else
|
|
||||||
pass()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif policy.yes_threshold then
|
|
||||||
if policy.no_threshold then
|
|
||||||
if #no_votes >= policy.no_threshold then
|
|
||||||
fail()
|
|
||||||
end
|
|
||||||
if #yes_votes >= policy.yes_threshold then
|
|
||||||
pass()
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif policy.consent_ratio and policy.quorum then
|
|
||||||
if quorum >= policy.quorum then
|
|
||||||
if consent_ratio >= policy.consent_ratio then
|
|
||||||
pass()
|
|
||||||
else
|
|
||||||
fail()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
policy_table_format = {
|
|
||||||
"create_child_org": {
|
|
||||||
defer_to = nil,
|
|
||||||
|
|
||||||
-- duration
|
|
||||||
duration = nil, -- evaluates end conditions when reached
|
|
||||||
|
|
||||||
-- thesholds
|
|
||||||
no_threshold = nil, -- fails if reached
|
|
||||||
yes_threshold = nil, -- succeeds if reached
|
|
||||||
|
|
||||||
--ratios
|
|
||||||
consent_ratio = nil, -- % of voters
|
|
||||||
quorum = nil, -- % of members that vote
|
|
||||||
}
|
|
||||||
"create_child_org": {
|
|
||||||
consent_threshold = 0.51,
|
|
||||||
max_duration = 89324, -- seconds until vote closes if threshold not reached, or nil for no limit
|
|
||||||
defer = nil, -- org id to defer to, or nil
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,278 +0,0 @@
|
|||||||
-- THIS IS NOW DEPRECATED, TO MERGE INTO PROCESS
|
|
||||||
|
|
||||||
|
|
||||||
-- REQUESTS
|
|
||||||
-- Provides request functionality to org
|
|
||||||
|
|
||||||
-- TODO
|
|
||||||
-- include consent functionality, available to modules
|
|
||||||
-- load available modules in modpol.lua
|
|
||||||
-- make policies a set of options for consent functions
|
|
||||||
-- create simple modules for core functions: change_policy, add_member, start_org, join_org, close_org
|
|
||||||
|
|
||||||
-- CONSENT
|
|
||||||
-- Provides consent functionality for modules
|
|
||||||
|
|
||||||
-- define default params
|
|
||||||
modpol.default_policy = {
|
|
||||||
target_org = nil,
|
|
||||||
time_limit = nil,
|
|
||||||
vote_threshold = 1 -- a ratio of the total number of members
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
-- PROCESSES
|
|
||||||
-- functions that enable requests to create processes
|
|
||||||
|
|
||||||
-- ================================
|
|
||||||
-- creates a new process linked to a request id
|
|
||||||
function modpol.orgs:create_process(process_type, request_id)
|
|
||||||
if not modpol.modules[process_type] then
|
|
||||||
modpol.ocutil.log('Process type "' .. process_type .. '" does not exist')
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local empty_index = nil
|
|
||||||
-- linear search for empty process slots (lazy deletion)
|
|
||||||
for k, v in ipairs(self.processes) do
|
|
||||||
if v == 'deleted' then
|
|
||||||
empty_index = k
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local index
|
|
||||||
-- attempts to fill empty spots in list, otherwise appends to end
|
|
||||||
if empty_index then
|
|
||||||
index = empty_index
|
|
||||||
else
|
|
||||||
index = #self.processes + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
-- retrieving requested module
|
|
||||||
local module = modpol.modules[process_type]
|
|
||||||
local new_process = module:new_process(index, request_id, self.id)
|
|
||||||
|
|
||||||
self.processes[index] = new_process
|
|
||||||
|
|
||||||
modpol.ocutil.log('Created process #' .. index .. ' - ' .. process_type .. ' for ' .. self.name)
|
|
||||||
self:record('Created process #' .. index .. ' - ' .. process_type, 'add_process')
|
|
||||||
|
|
||||||
return index
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ===========================
|
|
||||||
-- adds a new pending action to the org's table
|
|
||||||
function modpol.orgs:add_pending_action(process_id, user)
|
|
||||||
-- adds tables if they don't exist already
|
|
||||||
self.pending[user] = self.pending[user] or {}
|
|
||||||
-- flagging actual action
|
|
||||||
self.pending[user][process_id] = true
|
|
||||||
|
|
||||||
local message =
|
|
||||||
modpol.interactions.message(user, "New pending action in " .. self.name)
|
|
||||||
modpol.ocutil.log("Added pending action to " .. user .. " in process #" .. process_id .. ' from ' .. self.name)
|
|
||||||
self:record('Added pending action to ' .. user .. ' in process #' .. process_id, "add_pending_action")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ========================
|
|
||||||
-- removes a pending action from the org's table
|
|
||||||
function modpol.orgs:remove_pending_action(process_id, user)
|
|
||||||
|
|
||||||
if self.pending[user] then
|
|
||||||
self.pending[user][process_id] = nil
|
|
||||||
modpol.ocutil.log("Removed pending action from " .. user .. " in process #" .. process_id .. ' from ' .. self.name)
|
|
||||||
self:record('Removed pending action from ' .. user .. ' in process #' .. process_id, "del_pending_action")
|
|
||||||
else
|
|
||||||
modpol.ocutil.log("Could not remove pending action from " .. user .. " in process #" .. process_id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- =====================
|
|
||||||
-- removes all pending actions for a given process id from all users
|
|
||||||
function modpol.orgs:wipe_pending_actions(process_id)
|
|
||||||
for user in pairs(self.pending) do
|
|
||||||
self.pending[user][process_id] = nil
|
|
||||||
end
|
|
||||||
modpol.ocutil.log("Removed all pending actions for process #" .. process_id)
|
|
||||||
self:record('Removed all pending actions for process #' .. process_id, "del_pending_action")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ======================
|
|
||||||
-- returns a boolean to indicate whether a user has any active pending actions
|
|
||||||
function modpol.orgs:has_pending_actions(user)
|
|
||||||
-- next() will return the next pair in a table
|
|
||||||
-- if next() returns nil, the table is empty
|
|
||||||
if not self.pending[user] then
|
|
||||||
return false
|
|
||||||
else
|
|
||||||
if not next(self.pending[user]) then
|
|
||||||
return false
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ===========================
|
|
||||||
-- compares to requests to see if they are identical
|
|
||||||
function modpol.orgs.comp_req(req1, req2)
|
|
||||||
-- compares request type
|
|
||||||
if req1.type ~= req2.type then
|
|
||||||
return false
|
|
||||||
else
|
|
||||||
-- comparing parameters
|
|
||||||
-- we can assume the number of params is the same as this is checked in the make_request func
|
|
||||||
for k, v in ipairs(req1.params) do
|
|
||||||
if v ~= req2.params[k] then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ===============================
|
|
||||||
-- returns string of all active requests
|
|
||||||
function modpol.orgs:list_request()
|
|
||||||
local str
|
|
||||||
for id, req in ipairs(self.requests) do
|
|
||||||
if req ~= "deleted" then
|
|
||||||
if str then
|
|
||||||
str = str .. '\n' .. req.type .. ' (' .. req.user .. ') '
|
|
||||||
else
|
|
||||||
str = req.type .. ' (' .. req.user .. ') '
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ===============================
|
|
||||||
-- if the request was approved, the associated function is called, otherwise it is deleted
|
|
||||||
-- TODO Rather than hard-coding functions below, this should be given an arbitrary result function based on the request
|
|
||||||
function modpol.orgs:resolve_request(request_id, approve)
|
|
||||||
|
|
||||||
-- wipe actions
|
|
||||||
self:wipe_pending_actions(request_id)
|
|
||||||
|
|
||||||
if approve then
|
|
||||||
local request = self.requests[request_id]
|
|
||||||
local p = request.params
|
|
||||||
|
|
||||||
-- there's probably a way to clean this up, the issue is the varying number of commands
|
|
||||||
-- ex: self['add_member'](self, 'member_name')
|
|
||||||
-- not sure if this is safe, more testing to do
|
|
||||||
|
|
||||||
-- self[request.type](self, p[1], p[2], p[3])
|
|
||||||
|
|
||||||
if request.type == "add_org" then
|
|
||||||
self:add_org(request.params[1], request.user)
|
|
||||||
elseif request.type == "delete" then
|
|
||||||
self:delete()
|
|
||||||
elseif request.type == "add_member" then
|
|
||||||
self:add_member(request.params[1])
|
|
||||||
elseif request.type == "remove_member" then
|
|
||||||
self:remove_member(request.params[1])
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
self.processes[request_id] = "deleted"
|
|
||||||
modpol.ocutil.log('Deleted process #' .. request_id)
|
|
||||||
|
|
||||||
self.requests[request_id] = "deleted"
|
|
||||||
modpol.ocutil.log("Resolved request #" .. request_id .. ' in ' .. self.name)
|
|
||||||
|
|
||||||
self:record("Resolved request #" .. request_id, "resolve_request")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ================================
|
|
||||||
-- tries to make a request to the org
|
|
||||||
function modpol.orgs:make_request(request)
|
|
||||||
|
|
||||||
-- checking to see if identical request already exists
|
|
||||||
for k, v in ipairs(self.requests) do
|
|
||||||
if self.comp_req(request, v) == true then
|
|
||||||
modpol.ocutil.log('Error in ' .. self.name .. ':make_request -> request has already been made')
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- checking to see if user is able to make request
|
|
||||||
local requested_policy = self.policies[request.type]
|
|
||||||
|
|
||||||
-- if not the instance org (instance's don't have parents)
|
|
||||||
if self.id ~= 1 then
|
|
||||||
local parent_policy = modpol.orgs.get_org(self.parent).policies[request.type]
|
|
||||||
|
|
||||||
-- tries to use org's policy table, defers to parent otherwise
|
|
||||||
if not requested_policy then
|
|
||||||
modpol.ocutil.log(request.type .. ' policy not found, deferring to parent org')
|
|
||||||
requested_policy = parent_policy
|
|
||||||
|
|
||||||
if not parent_policy then
|
|
||||||
modpol.ocutil.log('Error in ' .. self.name .. ':make_request -> parent policy undefined')
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- fails if instance policy undefined
|
|
||||||
else
|
|
||||||
if not requested_policy then
|
|
||||||
modpol.ocutil.log('Error in ' .. self.name .. ':make_request -> policy undefined')
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- make sure user is allowed to make request
|
|
||||||
if requested_policy.must_be_member and not self:has_member(request.user) then
|
|
||||||
modpol.ocutil.log('Error in ' .. self.name .. ':make_request -> user must be org member to make this request')
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local empty_index = nil
|
|
||||||
-- linear search for empty process slots (lazy deletion)
|
|
||||||
for k, v in ipairs(self.requests) do
|
|
||||||
if v == 'deleted' then
|
|
||||||
empty_index = k
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- attempts to fill empty spots in list, otherwise appends to end
|
|
||||||
local request_id = nil
|
|
||||||
if empty_index then
|
|
||||||
self.requests[empty_index] = request
|
|
||||||
request_id = empty_index
|
|
||||||
else
|
|
||||||
table.insert(self.requests, request)
|
|
||||||
request_id = #self.requests
|
|
||||||
end
|
|
||||||
|
|
||||||
modpol.interactions.message(request.user, "Request made by " .. request.user .. " to " .. request.type .. " in " .. self.name)
|
|
||||||
modpol.ocutil.log("Request made by " .. request.user .. " to " .. request.type .. " in " .. self.name)
|
|
||||||
self:record("Request made by " .. request.user .. " to " .. request.type, "make_request")
|
|
||||||
|
|
||||||
-- launching process tied to this request
|
|
||||||
local process_id = self:create_process(requested_policy.process_type, request_id)
|
|
||||||
|
|
||||||
-- returns process id of processes launched by this request
|
|
||||||
return process_id
|
|
||||||
end
|
|
||||||
|
|
||||||
-- wrapper for process:interact function, ensures that user actually has a pending action for that process
|
|
||||||
function modpol.orgs:interact(process_id, user)
|
|
||||||
process = self.processes[process_id]
|
|
||||||
if self.pending[user] then
|
|
||||||
if self.pending[user][process_id] == true then
|
|
||||||
process:interact(user)
|
|
||||||
else
|
|
||||||
modpol.ocutil.log("Cannot interact with process, user does not have a valid pending action")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
modpol.ocutil.log("Cannot interact with process, user does not have any pending actions")
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
|||||||
-- ===================================================================
|
|
||||||
-- /users.lua
|
|
||||||
-- User-related functions for Modular Politics
|
|
||||||
-- Called by modpol.lua
|
|
||||||
|
|
||||||
-- ===================================================================
|
|
||||||
-- Function: modpol.list_users
|
|
||||||
-- Params: org
|
|
||||||
-- Outputs: Table of user names
|
|
||||||
--
|
|
||||||
-- This may be overwritten by the platform-specific interface
|
|
||||||
|
|
||||||
modpol.list_users = function(org)
|
|
||||||
local users = {}
|
|
||||||
if (org == nil) then -- no specified org; all players
|
|
||||||
if modpol.instance
|
|
||||||
and modpol.instance.members then
|
|
||||||
-- if instance exists and has membership
|
|
||||||
users = modpol.instance.members
|
|
||||||
else
|
|
||||||
users = {}
|
|
||||||
end
|
|
||||||
else -- if an org is specified
|
|
||||||
if (modpol.orgs[org] ~= nil) then -- org exists
|
|
||||||
users = modpol.orgs[org]["members"]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return users
|
|
||||||
end
|
|
@ -47,7 +47,7 @@ function modpol.interactions.dashboard(user)
|
|||||||
-- to add: nested orgs map
|
-- to add: nested orgs map
|
||||||
local all_orgs = modpol.orgs.list_all()
|
local all_orgs = modpol.orgs.list_all()
|
||||||
local user_orgs = modpol.orgs.user_orgs(user)
|
local user_orgs = modpol.orgs.user_orgs(user)
|
||||||
local all_users = modpol.list_users()
|
local all_users = modpol.instance:list_members()
|
||||||
-- set up formspec
|
-- set up formspec
|
||||||
local formspec = {
|
local formspec = {
|
||||||
"formspec_version[4]",
|
"formspec_version[4]",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user