Skip to content

Commit 53487fa

Browse files
committed
PIX-107 Admin and owner cant be banned
1 parent 60794a5 commit 53487fa

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

client/src/components/lobbies/UserListPanel.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ defineProps<{
99
users: User[];
1010
bannedUsers?: BannedUser[];
1111
canModerate?: boolean;
12+
ownerId?: string;
1213
}>();
1314
1415
const emit = defineEmits<{
@@ -83,7 +84,14 @@ const handleUnban = async (userId: string) => {
8384

8485
<div v-if="canModerate && user.id !== userStore.id" class="mod-actions">
8586
<button class="mod-btn kick" @click="handleKick(user.id)" title="Kick User">K</button>
86-
<button class="mod-btn ban" @click="handleBan(user.id)" title="Ban User">B</button>
87+
<button
88+
v-if="user.id !== ownerId && !user.isAdmin"
89+
class="mod-btn ban"
90+
@click="handleBan(user.id)"
91+
title="Ban User"
92+
>
93+
B
94+
</button>
8795
</div>
8896
</li>
8997
</ul>

client/src/stores/lobby.store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DISCONNECT_REASONS } from '../constants/disconnect.constants';
66
export interface User {
77
id: string;
88
username: string;
9+
isAdmin?: boolean;
910
}
1011

1112
export const useLobbyStore = defineStore('lobby', () => {

client/src/views/PlayView.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ onUnmounted(() => {
277277
:users="users"
278278
:banned-users="bannedUsers"
279279
:can-moderate="hasLobbyPermissions"
280+
:owner-id="lobbyOwnerId"
280281
@kick="handleKickUser"
281282
@ban="handleBanUser"
282283
@unban="handleUnbanUser"

server/src/controllers/lobby.controller.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ export class LobbyController {
185185
}
186186

187187
// Persist Ban
188+
const targetUser = await import('../models/User.js').then(m => m.User.findById(targetUserId));
189+
190+
if (!targetUser) {
191+
throw new AppError('User not found', 404);
192+
}
193+
194+
const isOwner = lobby.owner && (lobby.owner.toString() === targetUserId || (lobby.owner as any)._id?.toString() === targetUserId);
195+
const isAdmin = targetUser.isAdmin;
196+
197+
if (isOwner || isAdmin) {
198+
throw new AppError('Cannot ban lobby owner or admin', 403);
199+
}
200+
188201
await LobbyService.banUser(id, targetUserId);
189202
console.log(`[Lobby] Banning user ${targetUserId} from ${id}`);
190203

0 commit comments

Comments
 (0)