--- 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