Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/routes/event-handlers/action.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down