mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
no persist admin status
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -11,7 +11,7 @@
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
|
||||
<title>Multi Roomba Rover</title>
|
||||
<script type="module" crossorigin src="/assets/index-BFooYURt.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-DECQ2TrX.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-f8xLbmgU.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -164,11 +164,6 @@ function updateUserFromSocket(user, socket, identity) {
|
||||
user.socketIds.push(socket.id);
|
||||
changed = true;
|
||||
}
|
||||
if (ADMIN_ROLES.has(role) && !user.admin) {
|
||||
user.admin = true;
|
||||
user.adminName = socket?.data?.user?.username || null;
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
@@ -189,17 +184,12 @@ function ensureUserForSocket(socket) {
|
||||
lastRole: null,
|
||||
lastSocketId: null,
|
||||
lastIp: identity.ip || null,
|
||||
admin: false,
|
||||
adminName: null,
|
||||
};
|
||||
store.users[user.id] = user;
|
||||
}
|
||||
const changed = updateUserFromSocket(user, socket, identity);
|
||||
socket.data.moderation = { userId: user.id, ...identity };
|
||||
if (changed) {
|
||||
if (user.admin) {
|
||||
clearBansForUser(user, { reason: 'Admin role applied' });
|
||||
}
|
||||
saveStore(store);
|
||||
emitModerationSnapshot();
|
||||
}
|
||||
@@ -295,8 +285,6 @@ function serializeUser(user) {
|
||||
firstSeen: user.firstSeen || null,
|
||||
lastRole: user.lastRole || null,
|
||||
lastSocketId: user.lastSocketId || null,
|
||||
admin: Boolean(user.admin),
|
||||
adminName: user.adminName || null,
|
||||
ban: activeBan
|
||||
? {
|
||||
id: activeBan.id,
|
||||
@@ -380,15 +368,11 @@ function createBan(target, { durationMs = null, reason = null, createdBy = null
|
||||
const query = resolved.query || null;
|
||||
const user =
|
||||
resolved.userId ? store.users[resolved.userId] || null : findUserByQuery(query || resolved.socketId || resolved.nickname || resolved.clientId || resolved.visitorToken || resolved.ip);
|
||||
if (user && user.admin) {
|
||||
throw new Error('Admins cannot be banned.');
|
||||
}
|
||||
if (resolved.ip) {
|
||||
const adminMatch = Object.values(store.users || {}).some(
|
||||
(entry) => entry.admin && Array.isArray(entry.ips) && entry.ips.includes(resolved.ip),
|
||||
);
|
||||
if (adminMatch) {
|
||||
throw new Error('Admins cannot be banned.');
|
||||
const targetSocketId = resolved.socketId || user?.lastSocketId || null;
|
||||
if (targetSocketId) {
|
||||
const targetSocket = io.sockets.sockets.get(targetSocketId);
|
||||
if (targetSocket && isAdminSocket(targetSocket)) {
|
||||
throw new Error('Active admins cannot be banned.');
|
||||
}
|
||||
}
|
||||
const identity = {
|
||||
@@ -560,12 +544,8 @@ io.on('connection', (socket) => {
|
||||
roleEvents.on('change', ({ socket, role }) => {
|
||||
if (!socket) return;
|
||||
if (ADMIN_ROLES.has(role)) {
|
||||
const user = ensureUserForSocket(socket);
|
||||
if (user.admin) {
|
||||
clearBansForUser(user, { reason: 'Admin role applied', by: socket?.data?.user?.username || socket.id });
|
||||
emitModerationSnapshot();
|
||||
refreshSocketStatus(socket);
|
||||
}
|
||||
ensureUserForSocket(socket);
|
||||
refreshSocketStatus(socket);
|
||||
socket.emit('moderation:init', getModerationSnapshot());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -301,7 +301,6 @@ function ModerationPanel({ moderation, onBan, onTimeout, onUnban }) {
|
||||
.map((user) => {
|
||||
const label = user.nicknames?.[user.nicknames.length - 1] || user.id.slice(0, 6);
|
||||
const ban = user.ban || null;
|
||||
const isAdmin = Boolean(user.admin);
|
||||
return (
|
||||
<div key={user.id} className="surface-muted space-y-0.25 text-xs">
|
||||
<div className="flex flex-wrap items-center justify-between gap-0.5">
|
||||
@@ -310,11 +309,6 @@ function ModerationPanel({ moderation, onBan, onTimeout, onUnban }) {
|
||||
<span className="rounded bg-slate-800 px-1 text-[0.7rem] text-slate-300">
|
||||
{user.id.slice(0, 6)}
|
||||
</span>
|
||||
{isAdmin && (
|
||||
<span className="rounded bg-amber-500/30 px-1 text-[0.7rem] text-amber-200">
|
||||
Admin
|
||||
</span>
|
||||
)}
|
||||
{ban && (
|
||||
<span className="rounded bg-red-500/30 px-1 text-[0.7rem] text-red-200">
|
||||
{ban.expiresAt ? 'Timeout' : 'Banned'}
|
||||
@@ -326,7 +320,6 @@ function ModerationPanel({ moderation, onBan, onTimeout, onUnban }) {
|
||||
type="button"
|
||||
className="button-dark text-[0.7rem]"
|
||||
onClick={() => handleBan(user)}
|
||||
disabled={isAdmin}
|
||||
>
|
||||
Ban
|
||||
</button>
|
||||
@@ -334,7 +327,6 @@ function ModerationPanel({ moderation, onBan, onTimeout, onUnban }) {
|
||||
type="button"
|
||||
className="button-dark text-[0.7rem]"
|
||||
onClick={() => handleTimeout(user)}
|
||||
disabled={isAdmin}
|
||||
>
|
||||
Timeout
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user