forge
Explore
Log in

Don't you dare go Hollow

🔒 gate the whiteboard roster user lookup to admins

Browse files at this commit

c087533acfcc30f0848284b0733c6f4fd95b4fe5Burak BoduroğluParent: d77e975
  • fix
    • 🔒 gate the whiteboard roster user lookup to admins
Show full message
fix: 🔒 gate the whiteboard roster user lookup to admins
- whiteboard detail page called GET /users (admin-only) on mount to
  resolve participant ids to names, so every non-admin participant —
  the common case for a board — 403'd the instant the page opened
- the call is now made only when the viewer is an admin; below that it
  is never sent, and the current user's own name is resolved from their
  auth record instead, so a student sees their own name and raw ids for
  others rather than a failed request
- the board's stroke/epoch history is unaffected: those reads and the
  live socket are participant-scoped (CurrentUser), not role-gated
src/pages/whiteboard-page.tsxmodified+22 -7
@@ -26,6 +26,7 @@ import { SidePanel } from "@/components/ui/side-panel";
26 import { reassembleStrokes } from "@/lib/board-stroke-codec";26 import { reassembleStrokes } from "@/lib/board-stroke-codec";
27 import { strokesBounds, type DrawScene } from "@/lib/draw-stroke";27 import { strokesBounds, type DrawScene } from "@/lib/draw-stroke";
28 import { formatDateTime } from "@/lib/format";28 import { formatDateTime } from "@/lib/format";
29+import { hasMinRole } from "@/lib/roles";
29 import { useAuth } from "@/stores/auth-context";30 import { useAuth } from "@/stores/auth-context";
30 import { usePreferences, useT } from "@/stores/preferences-context";31 import { usePreferences, useT } from "@/stores/preferences-context";
31 32
@@ -65,13 +66,21 @@ function WhiteboardContent() {
65 }, "");66 }, "");
66 67
67 const [board] = createResource(id, (boardId) => getBoardById(boardId));68 const [board] = createResource(id, (boardId) => getBoardById(boardId));
68- const [users] = createResource(async () => {69+ // `GET /users` is admin-only, so only an admin can resolve the roster's ids
69- try {70+ // to names — every other role would just 403 the moment this page mounts.
70- return (await getUsers({ limit: 500 })).items;71+ // Gate the call by role: below admin it is never sent, and names fall back to
71- } catch {72+ // the id (with the current user resolved from their own auth record below).
72- return [];73+ const isAdmin = () => hasMinRole(auth.user()?.role, "admin");
73- }74+ const [users] = createResource(
74- });75+ () => (isAdmin() ? "admin" : null),
76+ async () => {
77+ try {
78+ return (await getUsers({ limit: 500 })).items;
79+ } catch {
80+ return [];
81+ }
82+ },
83+ );
75 84
76 // Live board state, seeded from the REST read and updated by the room's socket.85 // Live board state, seeded from the REST read and updated by the room's socket.
77 const [live, setLive] = createSignal<BoardLiveState>({});86 const [live, setLive] = createSignal<BoardLiveState>({});
@@ -95,6 +104,12 @@ function WhiteboardContent() {
95 const closed = () => live().closed ?? false;104 const closed = () => live().closed ?? false;
96 105
97 const nameOf = (userId: string) => {106 const nameOf = (userId: string) => {
107+ // The current user is always resolvable from their own auth record, even
108+ // when the admin-only roster lookup didn't run.
109+ if (userId === meId()) {
110+ const me = auth.user();
111+ if (me) return [me.name, me.surname].filter(Boolean).join(" ") || me.username;
112+ }
98 const u = (users() ?? []).find((x) => x.id === userId);113 const u = (users() ?? []).find((x) => x.id === userId);
99 if (!u) return userId;114 if (!u) return userId;
100 return [u.name, u.surname].filter(Boolean).join(" ") || u.username;115 return [u.name, u.surname].filter(Boolean).join(" ") || u.username;