basic interaction dashboard, interact callback function in consent module

This commit is contained in:
Luke Miller
2021-07-05 17:32:17 -04:00
parent 7318b8d664
commit 1be8e8b23d
5 changed files with 93 additions and 40 deletions
-7
View File
@@ -1,7 +0,0 @@
dofile("../modpol.lua")
print("Log in as which user?")
local username = io.read()
local org = modpol.dashboard(username)
modpol.interactions.org_dashboard(username, org)
+59 -32
View File
@@ -9,22 +9,45 @@ modpol.interactions = {}
-- DASHBOARDS
-- ==========
-- Function: modpol.dashboard(user)
function modpol.interactions.login()
print("Log in as which user?")
local username = io.read()
while true do
local org = modpol.interactions.dashboard(username)
if org then
modpol.interactions.org_dashboard(username, org)
else
break
end
end
end
-- Function: modpol.interactions.dashboard(user)
-- Params: user (string)
-- Q: Should this return a menu of commands relevant to the specific user?
-- Output: Displays a menu of commands to the user
-- TKTK currently just prints all of modpol---needs major improvement
function modpol.dashboard(user)
function modpol.interactions.dashboard(user)
print()
local user_orgs = modpol.orgs.user_orgs(user)
local org_list = modpol.orgs.list_all()
print('Select an org')
for i, org in ipairs(user_orgs) do
print('['..i..']'..' '..org)
for i, org_name in ipairs(org_list) do
local org = modpol.orgs.get_org(org_name)
local indicator = ""
if org:has_pending_actions(user) then
indicator = "*"
end
print('['..i..']'..' '..org_name..indicator)
end
local sel = io.read()
return user_orgs[tonumber(sel)]
local sel_org = org_list[tonumber(sel)]
if not sel_org then return end
modpol.interactions.org_dashboard(user, sel_org)
end
@@ -37,35 +60,39 @@ function modpol.interactions.org_dashboard(user, org_name)
local org = modpol.orgs.get_org(org_name)
if not org then return nil end
local is_member = org:has_member(user)
local membership_toggle = function()
local toggle_code = ""
if is_member then
toggle_code = "[Leave]"
else
toggle_code = "[Join]"
end
return toggle_code
end
local children = {}
for k,v in ipairs(org.children) do
local this_child = modpol.orgs.get_org(v)
table.insert(children, this_child.name)
end
local processes = {}
for k,v in ipairs(org.processes) do
print(k, v)
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 .. " (" .. this_request.type .. " -> " .. table.concat(this_request.params, ", ") .. ")" .. active
table.insert(processes, req_str)
end
end
-- set up output
local dashboard_table = {
"Org: " .. org_name,
membership_toggle(),
"Members: " .. table.concat(org.members, ", "),
"Children: " .. table.concat(children, ", "),
"Policies: " .. table.concat(org.policies, ", "),
"Processes: " .. table.concat(org.processes, ", "),
"[Add child]",
"[Remove org]",
"[Dashboard: modpol.dashboard()]"
}
-- present to player
print(table.concat(dashboard_table, "\n"))
print("Org: " .. org_name)
print("Members: " .. table.concat(org.members, ", "))
print("Children: " .. table.concat(children, ", "))
print("Processes: " .. table.concat(processes, ", "))
print('Interact with which process?')
local sel = io.read()
local process = org.processes[tonumber(sel)]
if not process then return end
process:interact(user)
end
-- ===================================================================
@@ -97,10 +124,10 @@ function modpol.interactions.binary_poll_user(user, question)
answer = io.read()
until answer == "y" or answer == "n" or answer == "a"
if answer == "y" then
return "Yes"
return "yes"
elseif answer == "n" then
return "No"
return "no"
else
return "Abstain"
return "abstain"
end
end