bugfixes to get delete and add_org requests to work. Working!

This commit is contained in:
Nathan Schneider 2021-08-04 22:47:02 -06:00
parent fa4283dce6
commit c26f11cd99
4 changed files with 30 additions and 33 deletions

View File

@ -1,5 +1,5 @@
-- ===================================================================
-- /orgs.lua
-- INTERACTIONS.LUA (CLI)
-- User interaction functions for Modular Politics
-- Called by modpol.lua
@ -177,10 +177,10 @@ function modpol.interactions.binary_poll_user(user, question, func)
until answer == "y" or answer == "n"
if answer == "y" then
modpol.interactions.message(user, "Response recorded")
func("yes")
func("Yes")
elseif answer == "n" then
modpol.interactions.message(user, "Response recorded")
func("no")
func("No")
else
modpol.interactions.message(user, "Error: invalid response")
end

View File

@ -46,29 +46,20 @@ function modpol.modules.consent:interact(user)
modpol.interactions.binary_poll_user(
user, "Do you consent?",
function(vote)
if vote == 'yes' then
if vote == 'Yes' then
self:approve(user, true)
elseif vote == 'no' then
elseif vote == 'No' then
self:approve(user, false)
end
end)
end
-- =========================================
-- function to delete a process, called when process finishes
function modpol.modules.consent:delete()
local process_org = modpol.orgs.get_org(self.org_id)
process_org:wipe_pending_actions(self.id)
process_org.processes[self.id] = "deleted"
modpol.ocutil.log('Deleted process #' .. self.id)
end
-- ======================================================
-- function for users to vote on a pending request
function modpol.modules.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
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
@ -97,11 +88,9 @@ function modpol.modules.consent:update_status()
if #self.votes_yes >= votes_needed then
modpol.ocutil.log('Request #' .. self.request_id .. ' passes')
process_org:resolve_request(self.request_id, true)
self:delete()
elseif #self.votes_no >= votes_needed then
modpol.ocutil.log('Request #' .. self.request_id .. ' fails to pass')
process_org:resolve_request(self.request_id, false)
self:delete()
else
modpol.ocutil.log('Waiting for more votes...')
end

View File

@ -70,11 +70,11 @@ 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")
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
-- ======================
@ -129,10 +129,15 @@ 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)
if approve then
local request = self.requests[request_id]
local p = request.params
-- 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')
@ -151,10 +156,13 @@ function modpol.orgs:resolve_request(request_id, approve)
end
end
self.requests[request_id] = "deleted"
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
@ -188,8 +196,8 @@ function modpol.orgs:make_request(request)
-- 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]
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')

View File

@ -227,7 +227,7 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
local new_request = {
user = pname,
type = "add_org",
params = {input,pname}
params = {input}
}
org:make_request(new_request)
modpol.interactions.message(pname,"requested")