adding to org dashboard, added check to make sure user is actually able to interact with process, set votes needed at process creation to prevent a stalemate if a user joins after
This commit is contained in:
parent
a6963ed84f
commit
76db1ea87f
@ -31,14 +31,14 @@ function modpol.interactions.dashboard(user)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print()
|
print('All users: ' .. table.concat(all_users, ', '))
|
||||||
print('Users: ' .. table.concat(all_users, ', '))
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
print('Access which org?')
|
print('Access which org?')
|
||||||
|
|
||||||
local sel = io.read()
|
local sel = io.read()
|
||||||
local sel_org = modpol.orgs.array[tonumber(sel)]
|
print()
|
||||||
|
local sel_org = modpol.orgs.array[tonumber(sel)].name
|
||||||
|
|
||||||
if not sel_org then return end
|
if not sel_org then return end
|
||||||
|
|
||||||
@ -49,45 +49,94 @@ end
|
|||||||
-- Function: modpol.interactions.org_dashboard
|
-- Function: modpol.interactions.org_dashboard
|
||||||
-- Params: user (string), org_name (string)
|
-- Params: user (string), org_name (string)
|
||||||
-- Output: Displays a menu of org-specific commands to the user
|
-- Output: Displays a menu of org-specific commands to the user
|
||||||
function modpol.interactions.org_dashboard(user, org)
|
function modpol.interactions.org_dashboard(user, org_name)
|
||||||
|
local org = modpol.orgs.get_org(org_name)
|
||||||
|
if not org then return nil end
|
||||||
|
|
||||||
|
local parent = ""
|
||||||
|
if org.id == 1 then
|
||||||
|
parent = "none"
|
||||||
|
else
|
||||||
|
parent = modpol.orgs.get_org(org.parent).name
|
||||||
|
end
|
||||||
|
|
||||||
local children = {}
|
local children = {}
|
||||||
for k,v in ipairs(org.children) do
|
for k,v in ipairs(org.children) do
|
||||||
local this_child = modpol.orgs.get_org(v)
|
local this_child = modpol.orgs.get_org(v)
|
||||||
table.insert(children, this_child.name)
|
table.insert(children, this_child.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
local processes = {}
|
local process_msg = #org.processes .. " total"
|
||||||
for k,v in ipairs(org.processes) do
|
|
||||||
print(k, v)
|
if org.pending[user] then
|
||||||
local this_request = org.requests[v.request_id]
|
process_msg = process_msg .. " (" .. #org.pending[user] .. " pending)"
|
||||||
if type(this_request) == "table" then
|
else
|
||||||
local active = ''
|
process_msg = process_msg .. " (0 pending)"
|
||||||
if org.pending[user] then
|
|
||||||
if org.pending[user][v.id] then
|
|
||||||
active = '*'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local req_str = "[" .. v.id .. "] " ..
|
|
||||||
active .. this_request.type
|
|
||||||
if this_request.params[1] then
|
|
||||||
req_str = req_str ": " ..
|
|
||||||
table.concat(this_request.params, ", ")
|
|
||||||
end
|
|
||||||
local req_str = v.id .. " (" .. this_request.type .. " -> " .. table.concat(this_request.params, ", ") .. ")" .. active
|
|
||||||
table.insert(processes, req_str)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- set up output
|
-- set up output
|
||||||
print("Org: " .. org_name)
|
print("Org: " .. org_name)
|
||||||
|
print("Parent: " .. parent)
|
||||||
print("Members: " .. table.concat(org.members, ", "))
|
print("Members: " .. table.concat(org.members, ", "))
|
||||||
print("Children: " .. table.concat(children, ", "))
|
print("Children: " .. table.concat(children, ", "))
|
||||||
print("Processes: " .. table.concat(processes, ", "))
|
print("Processes: " .. process_msg)
|
||||||
|
print()
|
||||||
|
print("Commands: (L)eave, (J)oin, (P)rocesses, (A)dd child, (D)elete org")
|
||||||
|
|
||||||
print('Interact with which process?')
|
|
||||||
local sel = io.read()
|
local sel = io.read()
|
||||||
local process = org.processes[tonumber(sel)]
|
print()
|
||||||
if not process then return end
|
|
||||||
process:interact(user)
|
if sel == 'l' or sel == 'L' then
|
||||||
|
org:remove_member(user)
|
||||||
|
|
||||||
|
elseif sel == 'j' or sel == 'J' then
|
||||||
|
org:make_request({user=user, type="add_member", params={user}})
|
||||||
|
|
||||||
|
elseif sel == 'a' or sel == 'A' then
|
||||||
|
print("What should the new org be named?")
|
||||||
|
local new_org_name = io.read()
|
||||||
|
org:make_request({user=user, type="add_org", params={new_org_name}})
|
||||||
|
|
||||||
|
elseif sel == 'd' or sel == 'D' then
|
||||||
|
org:make_request({user=user, type="delete", params={}})
|
||||||
|
|
||||||
|
elseif sel == 'p' or sel == 'P' then
|
||||||
|
local processes = {}
|
||||||
|
print("All processes: (* indicates pending action)")
|
||||||
|
for k,v in ipairs(org.processes) do
|
||||||
|
local this_request = org.requests[v.request_id]
|
||||||
|
if type(this_request) == "table" then
|
||||||
|
local active = ''
|
||||||
|
if org.pending[user] then
|
||||||
|
if org.pending[user][v.id] then
|
||||||
|
active = '*'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local req_str = "[" .. v.id .. "] " ..
|
||||||
|
active .. this_request.type
|
||||||
|
if this_request.params[1] then
|
||||||
|
req_str = req_str .. ": " ..
|
||||||
|
table.concat(this_request.params, ", ")
|
||||||
|
end
|
||||||
|
print(req_str)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
print()
|
||||||
|
print("Interact with which one?")
|
||||||
|
local to_interact = io.read()
|
||||||
|
local process = org.processes[tonumber(to_interact)]
|
||||||
|
if not process then return end
|
||||||
|
if org:has_pending_actions(user) then
|
||||||
|
if org.pending[user][process.id] then
|
||||||
|
process:interact(user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function: modpol.interactions.policy_dashboard
|
-- Function: modpol.interactions.policy_dashboard
|
||||||
|
7
modpol/interactions/login.lua
Normal file
7
modpol/interactions/login.lua
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
dofile("../modpol.lua")
|
||||||
|
|
||||||
|
print("Log in as which user?")
|
||||||
|
local username = io.read()
|
||||||
|
|
||||||
|
print()
|
||||||
|
modpol.interactions.dashboard(username)
|
@ -13,6 +13,7 @@ function temp_consent_process()
|
|||||||
request_id = nil,
|
request_id = nil,
|
||||||
total_votes = 0,
|
total_votes = 0,
|
||||||
majority_to_pass = 0.51,
|
majority_to_pass = 0.51,
|
||||||
|
votes_needed = nil,
|
||||||
votes_yes = {},
|
votes_yes = {},
|
||||||
votes_no = {}
|
votes_no = {}
|
||||||
}
|
}
|
||||||
@ -35,6 +36,8 @@ function modpol.modules.consent:new_process(id, request_id, org_id)
|
|||||||
p_org:add_pending_action(id, member)
|
p_org:add_pending_action(id, member)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
process.votes_needed = math.ceil(process.majority_to_pass * p_org:get_member_count())
|
||||||
|
|
||||||
return process
|
return process
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -82,13 +85,11 @@ end
|
|||||||
-- determines whether process has finished and resolves request if it has (unfinished)
|
-- determines whether process has finished and resolves request if it has (unfinished)
|
||||||
function modpol.modules.consent:update_status()
|
function modpol.modules.consent:update_status()
|
||||||
local process_org = modpol.orgs.get_org(self.org_id)
|
local process_org = modpol.orgs.get_org(self.org_id)
|
||||||
local eligible_voters = process_org:get_member_count()
|
|
||||||
local votes_needed = math.ceil(self.majority_to_pass * eligible_voters)
|
|
||||||
|
|
||||||
if #self.votes_yes >= votes_needed then
|
if #self.votes_yes >= self.votes_needed then
|
||||||
modpol.ocutil.log('Request #' .. self.request_id .. ' passes')
|
modpol.ocutil.log('Request #' .. self.request_id .. ' passes')
|
||||||
process_org:resolve_request(self.request_id, true)
|
process_org:resolve_request(self.request_id, true)
|
||||||
elseif #self.votes_no >= votes_needed then
|
elseif #self.votes_no >= self.votes_needed then
|
||||||
modpol.ocutil.log('Request #' .. self.request_id .. ' fails to pass')
|
modpol.ocutil.log('Request #' .. self.request_id .. ' fails to pass')
|
||||||
process_org:resolve_request(self.request_id, false)
|
process_org:resolve_request(self.request_id, false)
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user