From c087533acfcc30f0848284b0733c6f4fd95b4fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Sun, 2 Aug 2026 23:23:23 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=94=92=20gate=20the=20whiteboard?= =?UTF-8?q?=20roster=20user=20lookup=20to=20admins=20-=20whiteboard=20deta?= =?UTF-8?q?il=20page=20called=20GET=20/users=20(admin-only)=20on=20mount?= =?UTF-8?q?=20to=20=20=20resolve=20participant=20ids=20to=20names,=20so=20?= =?UTF-8?q?every=20non-admin=20participant=20=E2=80=94=20=20=20the=20commo?= =?UTF-8?q?n=20case=20for=20a=20board=20=E2=80=94=20403'd=20the=20instant?= =?UTF-8?q?=20the=20page=20opened=20-=20the=20call=20is=20now=20made=20onl?= =?UTF-8?q?y=20when=20the=20viewer=20is=20an=20admin;=20below=20that=20it?= =?UTF-8?q?=20=20=20is=20never=20sent,=20and=20the=20current=20user's=20ow?= =?UTF-8?q?n=20name=20is=20resolved=20from=20their=20=20=20auth=20record?= =?UTF-8?q?=20instead,=20so=20a=20student=20sees=20their=20own=20name=20an?= =?UTF-8?q?d=20raw=20ids=20for=20=20=20others=20rather=20than=20a=20failed?= =?UTF-8?q?=20request=20-=20the=20board's=20stroke/epoch=20history=20is=20?= =?UTF-8?q?unaffected:=20those=20reads=20and=20the=20=20=20live=20socket?= =?UTF-8?q?=20are=20participant-scoped=20(CurrentUser),=20not=20role-gated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/whiteboard-page.tsx | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/pages/whiteboard-page.tsx b/src/pages/whiteboard-page.tsx index 2eb3da2..46e9f5d 100644 --- a/src/pages/whiteboard-page.tsx +++ b/src/pages/whiteboard-page.tsx @@ -26,6 +26,7 @@ import { SidePanel } from "@/components/ui/side-panel"; import { reassembleStrokes } from "@/lib/board-stroke-codec"; import { strokesBounds, type DrawScene } from "@/lib/draw-stroke"; import { formatDateTime } from "@/lib/format"; +import { hasMinRole } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; import { usePreferences, useT } from "@/stores/preferences-context"; @@ -65,13 +66,21 @@ function WhiteboardContent() { }, ""); const [board] = createResource(id, (boardId) => getBoardById(boardId)); - const [users] = createResource(async () => { - try { - return (await getUsers({ limit: 500 })).items; - } catch { - return []; - } - }); + // `GET /users` is admin-only, so only an admin can resolve the roster's ids + // to names — every other role would just 403 the moment this page mounts. + // Gate the call by role: below admin it is never sent, and names fall back to + // the id (with the current user resolved from their own auth record below). + const isAdmin = () => hasMinRole(auth.user()?.role, "admin"); + const [users] = createResource( + () => (isAdmin() ? "admin" : null), + async () => { + try { + return (await getUsers({ limit: 500 })).items; + } catch { + return []; + } + }, + ); // Live board state, seeded from the REST read and updated by the room's socket. const [live, setLive] = createSignal({}); @@ -95,6 +104,12 @@ function WhiteboardContent() { const closed = () => live().closed ?? false; const nameOf = (userId: string) => { + // The current user is always resolvable from their own auth record, even + // when the admin-only roster lookup didn't run. + if (userId === meId()) { + const me = auth.user(); + if (me) return [me.name, me.surname].filter(Boolean).join(" ") || me.username; + } const u = (users() ?? []).find((x) => x.id === userId); if (!u) return userId; return [u.name, u.surname].filter(Boolean).join(" ") || u.username;