From cbc1be80d56d957f35f6124baa266366f6ffeb51 Mon Sep 17 00:00:00 2001 From: bh0fer Date: Mon, 31 Aug 2026 16:36:05 +0200 Subject: [PATCH] refine: allow nav actions for administrated users, without providing a student group --- src/routes/event-handlers/action.handler.ts | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/routes/event-handlers/action.handler.ts b/src/routes/event-handlers/action.handler.ts index 5bec771..787d55e 100644 --- a/src/routes/event-handlers/action.handler.ts +++ b/src/routes/event-handlers/action.handler.ts @@ -15,6 +15,42 @@ const onAction: ( .emit(IoEvent.ACTION, navRequest.action); return onDone(true); } + if (navRequest.roomIds.length === 0) { + // check that only administrated users receive the action + return prisma.user + .findMany({ + where: { + id: { in: navRequest.userIds }, + studentGroups: { + some: { + studentGroup: { + users: { + some: { + userId: user.id, + isAdmin: true + } + } + } + } + } + }, + distinct: ['id'], + select: { id: true } + }) + .then((users) => { + if (users.length > 0) { + socket + .to(users.map((u) => u.id)) + .except(socket.id) + .emit(IoEvent.ACTION, navRequest.action); + } + onDone(true); + }) + .catch((err) => { + console.error('Error checking user access for action', err); + onDone(false); + }); + } // check access first (navRequest.roomIds.length > 0 ? prisma.studentGroup