From c26f11cd9925a09cb5c521b544d8bf3c067b8c8d Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Wed, 4 Aug 2021 22:47:02 -0600 Subject: [PATCH] bugfixes to get delete and add_org requests to work. Working! --- modpol/interactions/interactions.lua | 8 ++--- modpol/modules/consent.lua | 21 +++--------- modpol/orgs/requests.lua | 32 ++++++++++++------- .../overrides/interactions/interactions.lua | 2 +- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/modpol/interactions/interactions.lua b/modpol/interactions/interactions.lua index e57c997..9e64603 100644 --- a/modpol/interactions/interactions.lua +++ b/modpol/interactions/interactions.lua @@ -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 diff --git a/modpol/modules/consent.lua b/modpol/modules/consent.lua index 25e767a..9be2b53 100644 --- a/modpol/modules/consent.lua +++ b/modpol/modules/consent.lua @@ -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 diff --git a/modpol/orgs/requests.lua b/modpol/orgs/requests.lua index c17d4bf..bccdf8d 100644 --- a/modpol/orgs/requests.lua +++ b/modpol/orgs/requests.lua @@ -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') diff --git a/modpol_minetest/overrides/interactions/interactions.lua b/modpol_minetest/overrides/interactions/interactions.lua index 73e9f91..3e964fe 100644 --- a/modpol_minetest/overrides/interactions/interactions.lua +++ b/modpol_minetest/overrides/interactions/interactions.lua @@ -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")