Add review permission.

This moves review into a separate permission, aside from "server".

The benefit is that we can grant this to more people without the
need to pass out "server" privs, which has a lot more powers than
needeed.

This doesn't grant noclip. This needs to be done separately. Scoring
will be disabled for those with the review priv.
This commit is contained in:
Auke Kok 2020-07-27 16:52:10 -07:00
parent 633b76717a
commit a153f771be
6 changed files with 28 additions and 25 deletions

View File

@ -49,13 +49,13 @@ dofile(modpath .. "/score.lua")
local areas = AreaStore("insidethebox")
function boxes.get_player_boxes(name)
local is_admin = minetest.check_player_privs(name, "server")
local can_review = minetest.check_player_privs(name, "review")
local boxes = {}
for id = 0, db.get_last_box_id() do
local meta = db.box_get_meta(id)
if (meta.type == db.BOX_TYPE and meta.meta and
meta.meta.builder and meta.meta.builder == name) or
(is_admin and meta.type == db.BOX_TYPE) then
(can_review and meta.type == db.BOX_TYPE) then
table.insert(boxes, {id = id,
name = meta.meta.box_name or "[Unnamed]",
status = meta.meta.status,

View File

@ -24,6 +24,8 @@ local FE = minetest.formspec_escape
local callback = {}
minetest.register_privilege("review", S("Player can review boxes"))
local function register_teleport(name, def)
local function teleport_update_particles(pos, pname)
local tm = math.random(10, 50) / 10
@ -492,7 +494,7 @@ function callback.series(player, fields, context)
local name = player:get_player_name()
-- minimum required permissions
if not minetest.check_player_privs(name, "server") then
if not minetest.check_player_privs(name, "review") then
return true
end
@ -624,14 +626,14 @@ do_creator_if = function(player, context)
end
f = f .. "]"
if minetest.check_player_privs(name, "server") then
if minetest.check_player_privs(name, "review") then
f = f .. "button[8.4,0;3.4,1;series;"..FE(S("Manage Series")).."]"
end
local limit = tonumber(player:get_attribute("box_create_limit") or "3")
if (minetest.check_player_privs(name, "create") and counts.editing + counts.submitted <= limit) or
minetest.check_player_privs(name, "server") then
minetest.check_player_privs(name, "review") then
context.cancreate = true
f = f .. "button[8.4,1;3.4,1;new;"..FE(S("Create new")).."]"
elseif not context.limitreached then
@ -642,7 +644,7 @@ do_creator_if = function(player, context)
if context.box and context.box.status == db.STATUS_EDITING then
f = f .. "button[8.4,3;3.4,1;submit;"..FE(S("Submit")).."]"
elseif minetest.check_player_privs(name, "server") and context.box and
elseif minetest.check_player_privs(name, "review") and context.box and
context.box.status == db.STATUS_SUBMITTED then
f = f .. "button[8.4,3;3.4,1;reject;"..FE(S("Reject")).."]"
f = f .. "button[8.4,4;3.4,1;accept;"..FE(S("Accept")).."]"
@ -650,7 +652,8 @@ do_creator_if = function(player, context)
f = f .. "button[8.4,3;3.4,1;retract;"..FE(S("Retract")).."]"
end
if not context.box or context.box.status == db.STATUS_EDITING then
if (not context.box or context.box.status == db.STATUS_EDITING) and
minetest.check_player_privs(name, "server") then
f = f .. "button[8.4,7;3.4,1;edit;"..FE(S("Edit")).."]"
elseif minetest.check_player_privs(name, "server") then
f = f .. "button[8.4,7;3.4,1;edit;"..FE(S("Force edit")).."]"
@ -711,7 +714,7 @@ function callback.boxes_create(player, fields, context)
return meta.meta.status
end
local is_admin = minetest.check_player_privs(name, "server")
local can_review = minetest.check_player_privs(name, "review")
-- sadly a function, because meta may be nil
local function is_builder(id)
@ -737,21 +740,21 @@ function callback.boxes_create(player, fields, context)
end
elseif fields.play and context.box then
local id = context.box.id
if is_admin or box_get_status(id) == db.STATUS_ACCEPTED or is_builder(id) then
if can_review or box_get_status(id) == db.STATUS_ACCEPTED or is_builder(id) then
minetest.chat_send_player(name, S("Playing box @1", tostring(id)))
minetest.registered_chatcommands["enter"].func(name, tostring(id))
end
return true
elseif fields.edit and context.box then
local id = context.box.id
if is_admin or (box_get_status(id) == db.STATUS_EDITING and is_builder(id)) then
if can_review or (box_get_status(id) == db.STATUS_EDITING and is_builder(id)) then
minetest.chat_send_player(name, S("Editing box @1", tostring(id)))
minetest.registered_chatcommands["edite"].func(name, tostring(id))
end
return true
elseif fields.submit and context.box then
local id = context.box.id
if is_admin or (box_get_status(id) == db.STATUS_EDITING and is_builder(id)) then
if can_review or (box_get_status(id) == db.STATUS_EDITING and is_builder(id)) then
if not meta then
meta = db.box_get_meta(id)
end
@ -768,7 +771,7 @@ function callback.boxes_create(player, fields, context)
return true
elseif fields.accept and context.box then
local id = context.box.id
if is_admin and box_get_status(id) == db.STATUS_SUBMITTED then
if can_review and box_get_status(id) == db.STATUS_SUBMITTED then
minetest.chat_send_player(name, S("Accepting box @1", tostring(id)))
announce.all(name .. " accepts box " .. tostring(id) .. "!")
announce.admins(name .. " accepts box " .. tostring(id) .. "!")
@ -789,7 +792,7 @@ function callback.boxes_create(player, fields, context)
return true
elseif fields.reject and context.box then
local id = context.box.id
if is_admin and box_get_status(id) == db.STATUS_SUBMITTED then
if can_review and box_get_status(id) == db.STATUS_SUBMITTED then
minetest.chat_send_player(name, S("Rejecting box @1", tostring(id)))
announce.all(name .. " rejects box " .. tostring(id))
announce.admins(name .. " rejects box " .. tostring(id))
@ -799,7 +802,7 @@ function callback.boxes_create(player, fields, context)
elseif fields.new and context.cancreate then
do_creator_size_if(player, context)
return
elseif fields.series and is_admin then
elseif fields.series and can_review then
do_series_if(player, {})
return
elseif fields.sizes then

View File

@ -46,7 +46,7 @@ function boxes.score(name, box_id, score_type, values)
local player_id = db.player_get_id(name)
if minetest.check_player_privs(name, "server") then
if minetest.check_player_privs(name, "review") then
return
end
local bmeta = db.box_get_meta(box_id)

View File

@ -40,7 +40,7 @@ local player_inventory = {}
local admin = {}
local function creative_allowed(player_name)
return boxes.players_editing_boxes[player_name] or minetest.check_player_privs(player_name, {server = true})
return boxes.players_editing_boxes[player_name] or minetest.check_player_privs(player_name, "review")
end
@ -61,7 +61,7 @@ function creative.init_creative_inventory(player)
local stack1 = inv:get_stack(from_list, from_index)
local stack2 = inv:get_stack(to_list, to_index)
if (not stack1 or admin[stack1:get_name()] or not stack2 or admin[stack2:get_name()]) and
not minetest.check_player_privs(player_name, {server = true}) then
not minetest.check_player_privs(player_name, "review") then
minetest.log("error", "Client accesses inventory illegally (allow_move) (privs)")
return 0
end
@ -81,7 +81,7 @@ function creative.init_creative_inventory(player)
return 0
end
if (not stack or admin[stack:get_name()]) and
not minetest.check_player_privs(player_name, {server = true}) then
not minetest.check_player_privs(player_name, "review") then
minetest.log("error", "Client accesses inventory illegally (allow_take) (privs)")
return 0
end
@ -144,7 +144,7 @@ function creative.register_tab(name, title, items)
title = title,
is_in_nav = function(self, player, context)
if name == "admin" then
return minetest.check_player_privs(player, {server = true})
return minetest.check_player_privs(player, "review")
end
return creative_allowed(player:get_player_name())
end,

View File

@ -138,7 +138,7 @@ minetest.register_tool("inspector:inspector", {
on_use = function(itemstack, user, pointed_thing)
if not user
or not minetest.check_player_privs(user, "server")
or not minetest.check_player_privs(user, "review")
and not boxes.players_editing_boxes[user:get_player_name()] then
return
end
@ -176,7 +176,7 @@ minetest.register_tool("inspector:inspector", {
end,
on_place = function(itemstack, user, pointed_thing)
if not user
or not minetest.check_player_privs(user, "server")
or not minetest.check_player_privs(user, "review")
and not boxes.players_editing_boxes[user:get_player_name()] then
return
end
@ -211,7 +211,7 @@ minetest.register_tool("inspector:inspector", {
minetest.register_chatcommand("inspect", {
params = "inspect",
description = S("Inspect a position"),
privs = {server = true},
privs = {review = true},
func = function(name, param)
local paramlist = {}
for p in string.gmatch(param, "%S+") do

View File

@ -314,7 +314,7 @@ minetest.register_on_joinplayer(function(player)
skin = default_skins[math.random(#default_skins)]
end
if minetest.check_player_privs(player, "server") then
if minetest.check_player_privs(player, "review") then
skin = skin .. "^skin_overlay_admin.png"
end
@ -410,7 +410,7 @@ sfinv.register_page("player:skin", {
on_player_receive_fields = function(self, player, context, fields)
if fields.skin then
local skin = "skin_" .. fields.skin:lower() .. ".png"
if minetest.check_player_privs(player, "server") then
if minetest.check_player_privs(player, "review") then
skin = skin .. "^skin_overlay_admin.png"
end
player:set_attribute("skin", skin)
@ -423,7 +423,7 @@ sfinv.register_page("player:skin", {
-- monitor players violating box boundries
local function check_player_is_in_box(name, box)
local player = minetest.get_player_by_name(name)
if not player or minetest.check_player_privs(player, "server") then
if not player or minetest.check_player_privs(player, "review") then
return
end
local pos = player:get_pos()