priv_to_org.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --- Set privilege to org members
  2. -- @module priv_to_org
  3. -- Allows initiator to grant a priv they have to all members of an org
  4. local priv_to_org = {
  5. name = "Set privilege to org members",
  6. slug = "priv_to_org",
  7. desc = "Allows initiator to grant a priv they have to all members of an org"
  8. }
  9. priv_to_org.data = {
  10. }
  11. priv_to_org.config = {
  12. }
  13. --- (Required): initiate function
  14. -- @param result (optional) Callback if this module is embedded in other modules
  15. -- @function initiate
  16. function priv_to_org:initiate(result)
  17. local player_privs = minetest.get_player_privs(self.initiator)
  18. -- construct table for display
  19. local player_privs_table = {"View..."}
  20. for k,v in pairs(player_privs) do
  21. if player_privs[k] then
  22. table.insert(player_privs_table,k)
  23. end
  24. end
  25. modpol.interactions.dropdown_query(
  26. self.initiator,
  27. "Which privilege do you want to share with members of "..self.org.name.."?",
  28. player_privs_table,
  29. function(input)
  30. modpol.interactions.org_dashboard(self.initiator,self.org.id)
  31. for i,member in ipairs(self.org.members) do
  32. local member_privs = minetest.get_player_privs(member)
  33. member_privs[input] = true
  34. minetest.set_player_privs(member, member_privs)
  35. end
  36. local message = self.initiator .. " added " .. input ..
  37. " privilege to all members of " .. self.org.name
  38. modpol.interactions.message_org(self.initiator, self.org.id, message)
  39. end)
  40. -- call result function
  41. if result then result() end
  42. end
  43. --- (Required) Add to module table
  44. modpol.modules.priv_to_org = priv_to_org