bugfixes to get delete and add_org requests to work. Working!
This commit is contained in:
parent
fa4283dce6
commit
c26f11cd99
@ -1,5 +1,5 @@
|
|||||||
-- ===================================================================
|
-- INTERACTIONS.LUA (CLI)
|
||||||
-- /orgs.lua
|
|
||||||
-- User interaction functions for Modular Politics
|
-- User interaction functions for Modular Politics
|
||||||
-- Called by modpol.lua
|
-- Called by modpol.lua
|
||||||
|
|
||||||
@ -177,10 +177,10 @@ function modpol.interactions.binary_poll_user(user, question, func)
|
|||||||
until answer == "y" or answer == "n"
|
until answer == "y" or answer == "n"
|
||||||
if answer == "y" then
|
if answer == "y" then
|
||||||
modpol.interactions.message(user, "Response recorded")
|
modpol.interactions.message(user, "Response recorded")
|
||||||
func("yes")
|
func("Yes")
|
||||||
elseif answer == "n" then
|
elseif answer == "n" then
|
||||||
modpol.interactions.message(user, "Response recorded")
|
modpol.interactions.message(user, "Response recorded")
|
||||||
func("no")
|
func("No")
|
||||||
else
|
else
|
||||||
modpol.interactions.message(user, "Error: invalid response")
|
modpol.interactions.message(user, "Error: invalid response")
|
||||||
end
|
end
|
||||||
|
@ -46,29 +46,20 @@ function modpol.modules.consent:interact(user)
|
|||||||
modpol.interactions.binary_poll_user(
|
modpol.interactions.binary_poll_user(
|
||||||
user, "Do you consent?",
|
user, "Do you consent?",
|
||||||
function(vote)
|
function(vote)
|
||||||
if vote == 'yes' then
|
if vote == 'Yes' then
|
||||||
self:approve(user, true)
|
self:approve(user, true)
|
||||||
elseif vote == 'no' then
|
elseif vote == 'No' then
|
||||||
self:approve(user, false)
|
self:approve(user, false)
|
||||||
end
|
end
|
||||||
end)
|
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 for users to vote on a pending request
|
||||||
function modpol.modules.consent:approve(user, decision)
|
function modpol.modules.consent:approve(user, decision)
|
||||||
if not modpol.orgs.get_org(self.org_id):has_member(user) then
|
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')
|
modpol.ocutil.log('Error in consent:approve -> user not a member of the org')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if decision then
|
if decision then
|
||||||
@ -97,11 +88,9 @@ function modpol.modules.consent:update_status()
|
|||||||
if #self.votes_yes >= votes_needed then
|
if #self.votes_yes >= 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)
|
||||||
self:delete()
|
|
||||||
elseif #self.votes_no >= votes_needed then
|
elseif #self.votes_no >= 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)
|
||||||
self:delete()
|
|
||||||
else
|
else
|
||||||
modpol.ocutil.log('Waiting for more votes...')
|
modpol.ocutil.log('Waiting for more votes...')
|
||||||
end
|
end
|
||||||
|
@ -70,11 +70,11 @@ end
|
|||||||
-- =====================
|
-- =====================
|
||||||
-- removes all pending actions for a given process id from all users
|
-- removes all pending actions for a given process id from all users
|
||||||
function modpol.orgs:wipe_pending_actions(process_id)
|
function modpol.orgs:wipe_pending_actions(process_id)
|
||||||
for user in pairs(self.pending) do
|
for user in pairs(self.pending) do
|
||||||
self.pending[user][process_id] = nil
|
self.pending[user][process_id] = nil
|
||||||
end
|
end
|
||||||
modpol.ocutil.log("Removed all pending actions for process #" .. process_id)
|
modpol.ocutil.log("Removed all pending actions for process #" .. process_id)
|
||||||
self:record('Removed all pending actions for process #' .. process_id, "del_pending_action")
|
self:record('Removed all pending actions for process #' .. process_id, "del_pending_action")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ======================
|
-- ======================
|
||||||
@ -129,10 +129,15 @@ end
|
|||||||
|
|
||||||
-- ===============================
|
-- ===============================
|
||||||
-- if the request was approved, the associated function is called, otherwise it is deleted
|
-- 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)
|
function modpol.orgs:resolve_request(request_id, approve)
|
||||||
if approve then
|
|
||||||
local request = self.requests[request_id]
|
-- wipe actions
|
||||||
local p = request.params
|
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
|
-- there's probably a way to clean this up, the issue is the varying number of commands
|
||||||
-- ex: self['add_member'](self, 'member_name')
|
-- ex: self['add_member'](self, 'member_name')
|
||||||
@ -151,10 +156,13 @@ function modpol.orgs:resolve_request(request_id, approve)
|
|||||||
end
|
end
|
||||||
|
|
||||||
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)
|
modpol.ocutil.log("Resolved request #" .. request_id .. ' in ' .. self.name)
|
||||||
|
|
||||||
self:record("Resolved request #" .. request_id, "resolve_request")
|
self:record("Resolved request #" .. request_id, "resolve_request")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -188,8 +196,8 @@ function modpol.orgs:make_request(request)
|
|||||||
|
|
||||||
-- if not the instance org (instance's don't have parents)
|
-- if not the instance org (instance's don't have parents)
|
||||||
if self.id ~= 1 then
|
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
|
-- tries to use org's policy table, defers to parent otherwise
|
||||||
if not requested_policy then
|
if not requested_policy then
|
||||||
modpol.ocutil.log(request.type .. ' policy not found, deferring to parent org')
|
modpol.ocutil.log(request.type .. ' policy not found, deferring to parent org')
|
||||||
|
@ -227,7 +227,7 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
local new_request = {
|
local new_request = {
|
||||||
user = pname,
|
user = pname,
|
||||||
type = "add_org",
|
type = "add_org",
|
||||||
params = {input,pname}
|
params = {input}
|
||||||
}
|
}
|
||||||
org:make_request(new_request)
|
org:make_request(new_request)
|
||||||
modpol.interactions.message(pname,"requested")
|
modpol.interactions.message(pname,"requested")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user