mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-19 09:37:50 -05:00
Staff roles with permissions, warnings, in-game staff commands
Moderators were one flag on the account. Now an account can hold a staff
role (lib/roles.js): helper, moderator or admin, each a list of named
permissions, with a higher role holding everything below it. An account
only marked `moderator` still counts as a moderator.
Every staff action checks the permission it needs, and staff never act
on staff of their own rank or above:
- warnings: kept on the account (who, when, the reason, a note for
staff), and shown to the player with the game's own warning popup for
the reason ("fw": inappropriate behavior, bullying, personal
information, scamming), which this server's strings already word as the
Burrow Rules.
- moderator panel: each action is checked against the role; new actions
"warn" (with a reason and note), "summon" (bring a player to the room you
are in) and "goto"; the player's page shows their warnings; GET
/mod/api/me returns your role and permissions, and the page hides the
buttons yours does not allow.
- in the game: !staff, !summon, !goto, !kick, !silence (HOURS, 0, or
off), !warn PLAYER [reason] [note], !warnings PLAYER and !message, for
staff whose role allows each, written to the moderators' log like the
panel's actions, marked "(in game)". To anyone else they are plain chat.
Usernames with spaces work.
- the login reply carries the player's own staffRole and
staffPermissions (empty for everyone else), so a client can show staff
tools only to staff.
- admin panel: a role picker on the account, "role" on POST
/admin/api/account, and GET /admin/api/roles listing what each allows.
The old moderator switch still works.
Also: the moderators' message box showed "--Message From Moderator--\n\n"
with the "\n" as written (strings 11134 and 11135 keep it as two
characters); they get real line breaks.
Staff powers need 2FA turned on, as the moderator panel already did. In
the game they come with the game session, which a trusted device opens
without a code; requiring a recent code there is left for later.
test/staff.js covers all of the above end to end.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
63dc43ebb3
commit
2fba9f1612
10 files changed
+756
-21
No files matched your search
+28
-6
@@ -18,6 +18,7 @@ const modlog = require("./modlog.js");
|
||||
const modpanel = require("./modpanel.js");
|
||||
const erase = require("./erase.js");
|
||||
const reports = require("./reports.js");
|
||||
const roles = require("./roles.js");
|
||||
const sales = require("./sales.js");
|
||||
const stats = require("./stats.js");
|
||||
const staff = require("./staff.js");
|
||||
@@ -148,7 +149,8 @@ const accountRow = (account, playing) => {
|
||||
// seconds left, -1 for permanent, 0 for not banned
|
||||
banned: ban,
|
||||
banReason: ban === 0 ? "" : account.banReason || bans.NO_REASON,
|
||||
moderator: Boolean(account.moderator),
|
||||
moderator: Boolean(roles.roleOf(account)),
|
||||
role: roles.roleOf(account),
|
||||
nameRejected: Boolean(account.nameRejected),
|
||||
silenced: world.moderation.isSilenced(account),
|
||||
animals: account.avatars.length,
|
||||
@@ -488,18 +490,33 @@ const act = (account, body) => {
|
||||
}
|
||||
// A moderator may use the moderator panel (lib/modpanel.js), with this
|
||||
// account's password and its 2FA, which it has to have.
|
||||
// (the older on/off switch; "role" below is the full one.)
|
||||
case "moderator":
|
||||
if (body.on === true) {
|
||||
account.moderator = true;
|
||||
}
|
||||
else {
|
||||
delete account.moderator;
|
||||
roles.setRole(account, body.on === true ? "moderator" : null);
|
||||
if (body.on !== true) {
|
||||
modpanel.forget(account);
|
||||
}
|
||||
accounts.save();
|
||||
return {ok: body.on === true
|
||||
? `${name} is a moderator.${totp.isOn(account) ? "" : " They have no 2FA yet and cannot sign in to the moderator panel until they turn it on."}`
|
||||
: `${name} is no longer a moderator.`};
|
||||
// A staff role (lib/roles.js): helper, moderator, admin, or none. What
|
||||
// each allows is listed under "GET /admin/api/roles".
|
||||
case "role": {
|
||||
const role = body.role === null || body.role === "" || body.role === "none" ? null : String(body.role);
|
||||
if (!roles.setRole(account, role)) {
|
||||
return {error: `No such role. Roles: ${Object.keys(roles.ROLES).join(", ")}, or none.`};
|
||||
}
|
||||
if (role === null) {
|
||||
modpanel.forget(account);
|
||||
}
|
||||
accounts.save();
|
||||
if (role === null) {
|
||||
return {ok: `${name} has no staff role.`};
|
||||
}
|
||||
const label = roles.ROLES[role].label.toLowerCase();
|
||||
return {ok: `${name} is now ${/^[aeiou]/.test(label) ? "an" : "a"} ${label}.${totp.isOn(account) ? "" : " They have no 2FA yet, so their role does nothing until they turn it on."}`};
|
||||
}
|
||||
case "rejectName":
|
||||
actions.rejectName(account, BY);
|
||||
manage.forget(account);
|
||||
@@ -692,6 +709,11 @@ const handle = async (req, res, url, from, web) => {
|
||||
return;
|
||||
|
||||
// who may use the moderator panel, and what each did there.
|
||||
// the staff roles and what each may do.
|
||||
case "GET /admin/api/roles":
|
||||
reply(200, {roles: Object.entries(roles.ROLES).map(([id, role]) => ({id, label: role.label, rank: role.rank, permissions: role.permissions})),
|
||||
permissions: roles.PERMISSIONS});
|
||||
return;
|
||||
case "GET /admin/api/moderators":
|
||||
reply(200, {moderators: modpanel.moderators(), log: modlog.recent()});
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user