diff --git a/modpol_core/api.lua b/modpol_core/api.lua index 707cdcb..45029c1 100644 --- a/modpol_core/api.lua +++ b/modpol_core/api.lua @@ -14,5 +14,6 @@ dofile (localdir .. "/interactions/interactions.lua") dofile (localdir .. "/modules/add_child_org.lua") dofile (localdir .. "/modules/consent.lua") dofile (localdir .. "/modules/join_org_consent.lua") +dofile (localdir .. "/modules/leave_org.lua") dofile (localdir .. "/modules/remove_org_consent.lua") dofile (localdir .. "/modules/remove_org.lua") diff --git a/modpol_core/modules/add_child_org.lua b/modpol_core/modules/add_child_org.lua index bad73b3..b0cf608 100644 --- a/modpol_core/modules/add_child_org.lua +++ b/modpol_core/modules/add_child_org.lua @@ -1,29 +1,62 @@ --- @module add_child_org -- Adds a child org +-- Depends on `consent` local add_child_org = { name = "Add child org", slug = "add_child_org", - desc = "Create a child org within the current one" + desc = "Create a child org within the current one with consent" } add_child_org.data = { + child_name = "" } add_child_org.config = { } -- @function initiate -function add_child_org:initiate(result) +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) - self.org:add_org(input, self.initiator) - modpol.interactions.message_org( - self.initiator, - self.org.id, - "Child org created: "..input) - modpol.interactions.dashboard(self.initiator) - end) + if input == "" then + modpol.interactions.message( + self.initiator, + "No name entered for child org") + self.org:wipe_pending_actions(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() + 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 + ) +end + --- (Required) Add to module table modpol.modules.add_child_org = add_child_org diff --git a/modpol_core/modules/consent.lua b/modpol_core/modules/consent.lua index 03983a6..885b847 100644 --- a/modpol_core/modules/consent.lua +++ b/modpol_core/modules/consent.lua @@ -16,7 +16,7 @@ consent.config = { votes_required = 1 } -function consent:initiate(result) +function consent:initiate(config, result) self.result = result -- if org is empty, consent is given automatically if self.org:get_member_count() == 0 then @@ -39,10 +39,10 @@ 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.result then self.result() end self.org:wipe_pending_actions(self.id) + if self.result then self.result() end end end ) diff --git a/modpol_core/modules/leave_org.lua b/modpol_core/modules/leave_org.lua index e69de29..ba5be73 100644 --- a/modpol_core/modules/leave_org.lua +++ b/modpol_core/modules/leave_org.lua @@ -0,0 +1,43 @@ +--- leave_org +-- @module leave_org + +local leave_org = { + name = "Leave org", + slug = "leave_org", + desc = "Leave this org" +} + +leave_org.data = { +} + +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) + if self.org == modpol.instance then + modpol.interactions.message( + self.initiator, + "You cannot leave the root org") + else + self.org:remove_member(self.initiator) + modpol.interactions.message_org( + self.initiator,self.org.id, + self.initiator .. " has left org " .. self.org.name) + modpol.interactions.message( + self.initiator, + "You have left org " .. self.org.name) + -- call result function + end + if result then result() end +end + +--- (Required) Add to module table +modpol.modules.leave_org = leave_org diff --git a/modpol_core/modules/remove_org.lua b/modpol_core/modules/remove_org.lua index 590771d..616c953 100644 --- a/modpol_core/modules/remove_org.lua +++ b/modpol_core/modules/remove_org.lua @@ -15,12 +15,18 @@ remove_org.data = {} --- Initiate function -- @function initiate function remove_org:initiate(config, result) - modpol.interactions.message_org( - self.initiator,self.org.id, - "Removing org: "..self.org.name) - self.org:delete() - modpol.interactions.dashboard(self.initiator) - -- call result function + if self.org == modpol.instance then + modpol.interactions.message( + self.initiator, + "You cannot remove the root org") + else + modpol.interactions.message_org( + self.initiator,self.org.id, + "Removing org: "..self.org.name) + self.org:delete() + modpol.interactions.dashboard(self.initiator) + -- call result function + end if result then result() end end diff --git a/modpol_core/modules/remove_org_consent.lua b/modpol_core/modules/remove_org_consent.lua index de5c305..0e8b0ca 100644 --- a/modpol_core/modules/remove_org_consent.lua +++ b/modpol_core/modules/remove_org_consent.lua @@ -33,7 +33,6 @@ function remove_org_consent:complete() self.initiator, self.org.id, "Removing org: " .. self.org.name) self.org:delete() - modpol.interactions.dashboard(self.initiator) end modpol.modules.remove_org_consent = remove_org_consent diff --git a/modpol_core/orgs/process.lua b/modpol_core/orgs/process.lua index 8f20761..e132524 100644 --- a/modpol_core/orgs/process.lua +++ b/modpol_core/orgs/process.lua @@ -90,12 +90,9 @@ end function modpol.orgs:interact(process_id, user) local process = self.processes[process_id] - modpol.interactions.message(user,"hi!") if self.pending[user] then - modpol.interactions.message(user,"id: "..process_id) local callback = self.pending[user][process_id] if callback then - modpol.interactions.message(user,"la!") process[callback](process, user) end end diff --git a/modpol_minetest/modules/priv_to_org.lua b/modpol_minetest/modules/priv_to_org.lua new file mode 100644 index 0000000..ac63a88 --- /dev/null +++ b/modpol_minetest/modules/priv_to_org.lua @@ -0,0 +1,49 @@ +--- Set privilege to org members +-- @module priv_to_org +-- Allows initiator to grant a priv they have to all members of an org + +local priv_to_org = { + name = "Set privilege to org members", + slug = "priv_to_org", + desc = "Allows initiator to grant a priv they have to all members of an org" +} + +priv_to_org.data = { +} + +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) + 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 + end + modpol.interactions.dropdown_query( + self.initiator, + "Which privilege do you want to share with members of "..self.org.name.."?", + player_privs, + function(input) + for member in self.org.members do + local member_privs = minetest.get_player_privs(member.name) + member_privs[input] = true + minetest.set_player_privs(member.name, member_privs) + end + local message = self.initiator .. " has set " .. input .. + " privilege to all members of " .. self.org.name + modpol.interactions.message_org(self.initiator,self.org.id, message) + end) + -- call result function + if result then result() end +end + +--- (Required) Add to module table +modpol.modules.priv_to_org = priv_to_org diff --git a/modpol_minetest/overrides/interactions.lua b/modpol_minetest/overrides/interactions.lua index 89e84c0..03aa55e 100644 --- a/modpol_minetest/overrides/interactions.lua +++ b/modpol_minetest/overrides/interactions.lua @@ -176,6 +176,12 @@ minetest.register_on_player_receive_fields(function (player, formname, fields) if formname == "modpol:org_dashboard" then local pname = player:get_player_name() local org = modpol.orgs.get_org(_contexts[pname].current_org) + -- just confirm the org still exists: + if not org then + modpol.interactions.message(pname, "Org no longer exists") + modpol.interactions.dashboard(pname) + return end + -- okay, onward if nil then elseif fields.join then org:add_member(pname)