diff --git a/modpol_core/interactions/interactions.lua b/modpol_core/interactions/interactions.lua
index 1dc8b7c..81de00a 100644
--- a/modpol_core/interactions/interactions.lua
+++ b/modpol_core/interactions/interactions.lua
@@ -228,11 +228,11 @@ end
-- ====================
-- Function: modpol.interactions.message_org
--- input: initiator (string), org_id (number), message (string)
+-- input: initiator (string), org (number or string), message (string)
-- output: broadcasts message to all org members
-function modpol.interactions.message_org(initiator, org_id, message)
- local org = modpol.orgs.get_org(org_id)
- local users = org:list_members()
+function modpol.interactions.message_org(initiator, org, message)
+ local this_org = modpol.orgs.get_org(org)
+ local users = this_org:list_members()
for k,v in ipairs(users) do
modpol.interactions.message(v, message)
end
diff --git a/modpol_core/modules/add_child_org.lua b/modpol_core/modules/add_child_org.lua
index b0cf608..933b087 100644
--- a/modpol_core/modules/add_child_org.lua
+++ b/modpol_core/modules/add_child_org.lua
@@ -15,12 +15,6 @@ add_child_org.config = {
-- @function initiate
function add_child_org:initiate(config, result)
- self.org:add_pending_action(
- self.id, self.initiator,
- "name_child_org")
-end
-
-function add_child_org:name_child_org()
modpol.interactions.text_query(
self.initiator,"Child org name: ",
function(input)
@@ -28,34 +22,38 @@ function add_child_org:name_child_org()
modpol.interactions.message(
self.initiator,
"No name entered for child org")
- self.org:wipe_pending_actions(self.id)
+ self.org:delete_process(self.id)
return end
self.data.child_name = input
modpol.interactions.message(
self.initiator,
"Proposed child org: " .. input)
- self.org:wipe_pending_actions(self.id)
- self:propose_child_org()
+ -- initiate consent process
+ self.org:call_module(
+ "consent",
+ self.initiator,
+ {
+ prompt = "Create child org " ..
+ self.data.child_name .. "?",
+ votes_required = #self.org.members
+ },
+ function()
+ self:create_child_org()
+ end
+ )
+ modpol.interactions.org_dashboard(
+ self.initiator, self.org.name)
end
)
end
-function add_child_org:propose_child_org()
- self.org:call_module(
- "consent",
- self.initiator,
- {
- prompt = "Create child org " .. self.data.child_name .. "?",
- votes_required = #self.org.members
- },
- function()
- self.org:add_org(self.data.child_name, self.initiator)
- modpol.interactions.message_org(
- self.initiator,
- self.org.id,
- "Child org created: "..self.data.child_name)
- end
- )
+function add_child_org:create_child_org()
+ self.org:add_org(self.data.child_name, self.initiator)
+ modpol.interactions.message_org(
+ self.initiator,
+ self.org.name,
+ "Child org created: "..self.data.child_name)
+ self.org:delete_process(self.id)
end
--- (Required) Add to module table
diff --git a/modpol_core/modules/consent.lua b/modpol_core/modules/consent.lua
index 885b847..e936b39 100644
--- a/modpol_core/modules/consent.lua
+++ b/modpol_core/modules/consent.lua
@@ -8,7 +8,7 @@ local consent = {
}
consent.data = {
- votes = 0
+ votes = 0
}
consent.config = {
@@ -16,11 +16,12 @@ consent.config = {
votes_required = 1
}
-function consent:initiate(config, result)
- self.result = result
+function consent:initiate(result)
+ self.data.result = result
-- if org is empty, consent is given automatically
if self.org:get_member_count() == 0 then
- self.result()
+ if self.data.result then
+ self.data.result() end
self.org:wipe_pending_actions(self.id)
else
-- otherwise, create poll
@@ -39,14 +40,14 @@ function consent:callback(member)
if resp == "Yes" then
self.data.votes = self.data.votes + 1
end
-
if self.data.votes >= self.config.votes_required then
+ if self.data.result then
+ self.data.result() end
self.org:wipe_pending_actions(self.id)
- if self.result then self.result() end
+ self.org:delete_process(self.id)
end
end
)
end
-
modpol.modules.consent = consent
diff --git a/modpol_core/modules/join_org.lua b/modpol_core/modules/join_org.lua
index 3806685..23d277b 100644
--- a/modpol_core/modules/join_org.lua
+++ b/modpol_core/modules/join_org.lua
@@ -7,19 +7,19 @@ join_org.setup = {
desc = "If consent process is passed, initiator joins this org."
}
-function join_org.initiate(initiator, org, result)
+function join_org.initiate(result)
modpol.interactions.binary_poll_user(
initiator,
"Would you like to join " .. org.name,
function (resp)
if resp == "Yes" then
- org:add_member(initiator)
+ self.org:add_member(self.initiator)
end
end
)
- for i, member in ipairs(org.members) do
- org:add_pending_action(
+ for i, member in ipairs(self.org.members) do
+ self.org:add_pending_action(
member,
function ()
modpol.interactions.binary_poll_user(
diff --git a/modpol_core/modules/join_org_consent.lua b/modpol_core/modules/join_org_consent.lua
index 9228dc7..e40e023 100644
--- a/modpol_core/modules/join_org_consent.lua
+++ b/modpol_core/modules/join_org_consent.lua
@@ -14,7 +14,7 @@ join_org_consent.data = {
join_org_consent.config = {
}
-function join_org_consent:initiate()
+function join_org_consent:initiate(result)
self.org:call_module(
"consent",
self.initiator,
@@ -26,6 +26,7 @@ function join_org_consent:initiate()
self:complete()
end
)
+ if result then result() end
end
function join_org_consent:complete()
diff --git a/modpol_core/modules/leave_org.lua b/modpol_core/modules/leave_org.lua
index ba5be73..bbc0c42 100644
--- a/modpol_core/modules/leave_org.lua
+++ b/modpol_core/modules/leave_org.lua
@@ -15,13 +15,9 @@ leave_org.config = {
--- (Required): initiate function
-- Modules have access to the following instance variables:
---
self.org
(the org the module was called in),
--- self.initiator
(the user that callced the module),
--- self.id
(the process id of the module instance)
--- @param config (optional) If user wants to override fields in the config table
-- @param result (optional) Callback if this module is embedded in other modules
-- @function initiate
-function leave_org:initiate(config, result)
+function leave_org:initiate(result)
if self.org == modpol.instance then
modpol.interactions.message(
self.initiator,
@@ -34,7 +30,6 @@ function leave_org:initiate(config, result)
modpol.interactions.message(
self.initiator,
"You have left org " .. self.org.name)
- -- call result function
end
if result then result() end
end
diff --git a/modpol_core/modules/remove_org.lua b/modpol_core/modules/remove_org.lua
index 616c953..9c3bbc6 100644
--- a/modpol_core/modules/remove_org.lua
+++ b/modpol_core/modules/remove_org.lua
@@ -1,5 +1,5 @@
--- @module Remove Org
--- A simple module that calls a consent process on an org to remove it.
+-- A simple module that removes an org.
--- Main module table
@@ -14,7 +14,7 @@ remove_org.data = {}
--- Initiate function
-- @function initiate
-function remove_org:initiate(config, result)
+function remove_org:initiate(result)
if self.org == modpol.instance then
modpol.interactions.message(
self.initiator,
diff --git a/modpol_core/modules/remove_org_consent.lua b/modpol_core/modules/remove_org_consent.lua
index 0e8b0ca..d5f5973 100644
--- a/modpol_core/modules/remove_org_consent.lua
+++ b/modpol_core/modules/remove_org_consent.lua
@@ -14,7 +14,7 @@ remove_org_consent.data = {
remove_org_consent.config = {
}
-function remove_org_consent:initiate()
+function remove_org_consent:initiate(result)
self.org:call_module(
"consent",
self.initiator,
@@ -26,6 +26,9 @@ function remove_org_consent:initiate()
self:complete()
end
)
+ modpol.interactions.org_dashboard(
+ self.initiator, self.org.name)
+ if result then result() end
end
function remove_org_consent:complete()
diff --git a/modpol_core/modules/template.lua b/modpol_core/modules/template.lua
index 7358e57..1232e52 100644
--- a/modpol_core/modules/template.lua
+++ b/modpol_core/modules/template.lua
@@ -35,10 +35,9 @@ module_template.config = {
-- self.org
(the org the module was called in),
-- self.initiator
(the user that callced the module),
-- self.id
(the process id of the module instance)
--- @param config (optional) If user wants to override fields in the config table
-- @param result (optional) Callback if this module is embedded in other modules
-- @function initiate
-function module_template:initiate(config, result)
+function module_template:initiate(result)
-- call interaction functions here!
-- call result function
diff --git a/modpol_core/orgs/process.lua b/modpol_core/orgs/process.lua
index e132524..8961a1a 100644
--- a/modpol_core/orgs/process.lua
+++ b/modpol_core/orgs/process.lua
@@ -60,6 +60,8 @@ end
function modpol.orgs:add_pending_action(process_id, user, callback)
self.pending[user] = self.pending[user] or {}
self.pending[user][process_id] = callback
+ modpol.interactions.message(
+ user, "New pending action in org "..self.name)
end
function modpol.orgs:remove_pending_action(process_id, user)
diff --git a/modpol_core/util/ocutil/ocutil.lua b/modpol_core/util/ocutil/ocutil.lua
index f943be4..940d7a2 100644
--- a/modpol_core/util/ocutil/ocutil.lua
+++ b/modpol_core/util/ocutil/ocutil.lua
@@ -97,7 +97,7 @@ modpol.ocutil.log = function (s)
if modpol.ocutil.logdir ~= nil and
modpol.ocutil.logname ~= nil then
- s = s .. "\n" -- Add trailing newline
+ s = s .. "\n" -- Add trailing newline
local logpath = modpol.ocutil.logdir .. "/" .. modpol.ocutil.logname
modpol.ocutil.file_append (logpath, s)
diff --git a/modpol_minetest/modules/priv_to_org.lua b/modpol_minetest/modules/priv_to_org.lua
index ac63a88..03e19a3 100644
--- a/modpol_minetest/modules/priv_to_org.lua
+++ b/modpol_minetest/modules/priv_to_org.lua
@@ -15,31 +15,30 @@ priv_to_org.config = {
}
--- (Required): initiate function
--- Modules have access to the following instance variables:
--- self.org
(the org the module was called in),
--- self.initiator
(the user that callced the module),
--- self.id
(the process id of the module instance)
--- @param config (optional) If user wants to override fields in the config table
-- @param result (optional) Callback if this module is embedded in other modules
-- @function initiate
-function priv_to_org:initiate(config, result)
+function priv_to_org:initiate(result)
local player_privs = minetest.get_player_privs(self.initiator)
- for i,v in ipairs(player_privs) do
- if not v then table.remove(player_privs,i) end
+ -- construct table for display
+ local player_privs_table = {"View..."}
+ for k,v in pairs(player_privs) do
+ if player_privs[k] then
+ table.insert(player_privs_table,k)
+ end
end
modpol.interactions.dropdown_query(
self.initiator,
"Which privilege do you want to share with members of "..self.org.name.."?",
- player_privs,
+ player_privs_table,
function(input)
- for member in self.org.members do
- local member_privs = minetest.get_player_privs(member.name)
+ for i,member in ipairs(self.org.members) do
+ local member_privs = minetest.get_player_privs(member)
member_privs[input] = true
- minetest.set_player_privs(member.name, member_privs)
+ minetest.set_player_privs(member, member_privs)
end
- local message = self.initiator .. " has set " .. input ..
+ local message = self.initiator .. " added " .. input ..
" privilege to all members of " .. self.org.name
- modpol.interactions.message_org(self.initiator,self.org.id, message)
+ modpol.interactions.message_org(self.initiator, self.org.id, message)
end)
-- call result function
if result then result() end
diff --git a/modpol_minetest/overrides/interactions.lua b/modpol_minetest/overrides/interactions.lua
index 03aa55e..7346bc5 100644
--- a/modpol_minetest/overrides/interactions.lua
+++ b/modpol_minetest/overrides/interactions.lua
@@ -223,8 +223,16 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
elseif fields.modules
and fields.modules ~= "View..." then
local module = fields.modules
- org:call_module(module, pname)
- modpol.interactions.org_dashboard(pname,org.name)
+ modpol.interactions.binary_poll_user(
+ pname,
+ modpol.modules[module].name.."\n"..
+ modpol.modules[module].desc.."\n"..
+ "Proceed?",
+ function(input)
+ if input == "Yes" then
+ org:call_module(module, pname)
+ end
+ end)
-- Receiving actions
elseif fields.actions
@@ -258,14 +266,16 @@ function modpol.interactions.policy_dashboard(
end
--- BASIC INTERACTION FUNCTIONS
--- ===========================
+-- INTERACTION FUNCTIONS
+-- =====================
-- Function: modpol.interactions.message
-- input: user (string), message (string)
-- output: displays message to specified user
function modpol.interactions.message(user, message)
- minetest.chat_send_player(user, message)
+ if message then
+ minetest.chat_send_player(user, message)
+ end
end
-- Function: modpol.interactions.text_query
@@ -331,11 +341,13 @@ end
minetest.register_on_player_receive_fields(function (player, formname, fields)
if formname == "modpol:dropdown_query" then
local pname = player:get_player_name()
- if fields.cancel ~= "cancel" then
+ if fields.cancel == "cancel" then
+ -- cancel, do nothing
+ else
local choice = fields.input
local func = _contexts[pname]["dropdown_query_func"]
if not choice then
- -- no choice, do nothing
+ -- empty, do nothing
elseif func then
func(choice)
else
@@ -355,10 +367,10 @@ function modpol.interactions.binary_poll_user(user, question, func)
-- set up formspec
local formspec = {
"formspec_version[4]",
- "size[5,3]",
+ "size[8,4]",
"label[0.375,0.5;",minetest.formspec_escape(question), "]",
- "button[1,1.5;1,0.8;yes;Yes]",
- "button[2,1.5;1,0.8;no;No]",
+ "button[1,2.5;1,0.8;yes;Yes]",
+ "button[2,2.5;1,0.8;no;No]",
--TODO can we enable text wrapping?
--TODO we could use scroll boxes to contain the text
}
@@ -377,7 +389,6 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
elseif fields.no then vote = fields.no
end
if vote then
- modpol.interactions.message(pname, "Responded " .. vote)
local func = _contexts[pname]["binary_poll_func"]
if func then func(vote) end
end