forge
Explore
Log in

Don't you dare go Hollow

Exam presence, board hub and chatbot limiter keys are school-scoped

Browse files at this commit

4f92feaebc0116acf1f745e5f51bb06f959de677Ahmet Kaan GümüşParent: b7dfc0c
  • fix
    • exam presence, board hub and chatbot limiter keys are school-scoped
Show full message
🔒 fix: exam presence, board hub and chatbot limiter keys are school-scoped

In-process maps were keyed by bare record keys, which two schools' databases
can now hand out identically. `state::scoped_key` is the only key
constructor; the maps take the slug themselves so no caller can pass an
unscoped key.
src/state.rsmodified+90 -28
@@ -8,7 +8,7 @@ use tokio::sync::broadcast;
88 use crate::ai::AiBridge;
99 use crate::database::Database;
1010 use crate::rate_limit::{RateLimitConfig, UserRateLimiter};
11-use crate::tenant::Tenants;
11+use crate::tenant::{Slug, Tenants};
1212
1313 /// Shared application state handed to every handler.
1414 #[derive(Clone)]
@@ -88,8 +88,20 @@ impl DbHealth {
8888 }
8989 }
9090
91+/// The map key for `key` inside `slug`'s school. One process serves every
92+/// school, but record keys are only unique *within* a database, so an
93+/// unscoped key would put two schools' identical attempts (or boards) in the
94+/// same room. The maps below are the only users of this, and their methods
95+/// take a [`Slug`] rather than a ready-made key — there is no way to reach one
96+/// with an unscoped string. The per-user chatbot limiter keys through here
97+/// too, for the same reason. A slug cannot contain `:`, so the join is
98+/// unambiguous.
99+pub fn scoped_key(slug: &Slug, key: &str) -> String {
100+ format!("{slug}:{key}")
101+}
102+
91103 /// How many exam-room sockets each attempt has open right now, keyed by the
92-/// attempt's record key. The room counts itself in on entry and out on exit,
104+/// attempt's record key within its school. The room counts itself in on entry and out on exit,
93105 /// and only the last socket out stamps the walk-out (`left_at`) — a student
94106 /// closing one of two tabs never counts as having left the exam.
95107 ///
@@ -103,14 +115,15 @@ pub struct ExamPresence(Arc<Mutex<HashMap<String, usize>>>);
103115
104116 impl ExamPresence {
105117 /// Count one socket into `attempt`'s room.
106- pub fn enter(&self, attempt: &str) {
118+ pub fn enter(&self, slug: &Slug, attempt: &str) {
107119 let mut rooms = self.0.lock().expect("exam presence lock");
108- *rooms.entry(attempt.to_string()).or_insert(0) += 1;
120+ *rooms.entry(scoped_key(slug, attempt)).or_insert(0) += 1;
109121 }
110122
111123 /// Count one socket out of `attempt`'s room; `true` when it was the last
112124 /// one — the student has actually left.
113- pub fn leave(&self, attempt: &str) -> bool {
125+ pub fn leave(&self, slug: &Slug, attempt: &str) -> bool {
126+ let attempt = &scoped_key(slug, attempt);
114127 let mut rooms = self.0.lock().expect("exam presence lock");
115128 match rooms.get_mut(attempt) {
116129 Some(count) if *count > 1 => {
@@ -128,7 +141,8 @@ impl ExamPresence {
128141 }
129142 }
130143
131-/// One broadcast channel per live whiteboard, keyed by the board's record key,
144+/// One broadcast channel per live whiteboard, keyed by the board's record key
145+/// within its school,
132146 /// so a stroke saved by one socket reaches every *other* socket in that board.
133147 /// Nothing else in this codebase fans out — an exam room only ever replies to
134148 /// the socket that spoke — so this is the only multi-subscriber push we have.
@@ -145,10 +159,10 @@ pub struct BoardHub(Arc<Mutex<HashMap<String, (broadcast::Sender<String>, usize)
145159 impl BoardHub {
146160 /// Count one socket into `board` and hand back its stream of other
147161 /// people's frames, creating the channel on the first join.
148- pub fn subscribe(&self, board: &str) -> broadcast::Receiver<String> {
162+ pub fn subscribe(&self, slug: &Slug, board: &str) -> broadcast::Receiver<String> {
149163 let mut boards = self.0.lock().expect("board hub lock");
150164 let room = boards
151- .entry(board.to_string())
165+ .entry(scoped_key(slug, board))
152166 .or_insert_with(|| (broadcast::channel(crate::constant::BOARD_HUB_CAPACITY).0, 0));
153167 room.1 += 1;
154168 room.0.subscribe()
@@ -156,10 +170,10 @@ impl BoardHub {
156170
157171 /// Push `frame` to every socket currently subscribed to `board`. A send
158172 /// with no receivers left is the normal empty-room case, not a failure.
159- pub fn publish(&self, board: &str, frame: String) {
173+ pub fn publish(&self, slug: &Slug, board: &str, frame: String) {
160174 let sender = {
161175 let boards = self.0.lock().expect("board hub lock");
162- boards.get(board).map(|room| room.0.clone())
176+ boards.get(&scoped_key(slug, board)).map(|room| room.0.clone())
163177 };
164178 if let Some(sender) = sender {
165179 let _ = sender.send(frame);
@@ -167,7 +181,8 @@ impl BoardHub {
167181 }
168182
169183 /// Count one socket out of `board`; the last one out drops the channel.
170- pub fn leave(&self, board: &str) {
184+ pub fn leave(&self, slug: &Slug, board: &str) {
185+ let board = &scoped_key(slug, board);
171186 let mut boards = self.0.lock().expect("board hub lock");
172187 match boards.get_mut(board) {
173188 Some(room) if room.1 > 1 => room.1 -= 1,
@@ -184,47 +199,94 @@ impl BoardHub {
184199 mod tests {
185200 use super::*;
186201
202+ fn slug(value: &str) -> Slug {
203+ Slug::try_new(value).expect(value)
204+ }
205+
187206 #[tokio::test]
188207 async fn every_subscriber_gets_the_stroke_and_the_room_is_reclaimed() {
208+ let a = slug("alpha");
189209 let hub = BoardHub::default();
190- let mut alice = hub.subscribe("board-a");
191- let mut bob = hub.subscribe("board-a");
192- hub.publish("board-a", "stroke".to_string());
210+ let mut alice = hub.subscribe(&a, "board-a");
211+ let mut bob = hub.subscribe(&a, "board-a");
212+ hub.publish(&a, "board-a", "stroke".to_string());
193213 assert_eq!(alice.recv().await.expect("alice"), "stroke");
194214 assert_eq!(bob.recv().await.expect("bob"), "stroke");
195215
196216 // Boards are independent, and publishing into an empty one is a no-op.
197- hub.publish("board-b", "nobody home".to_string());
198- assert!(!hub.0.lock().unwrap().contains_key("board-b"));
217+ hub.publish(&a, "board-b", "nobody home".to_string());
218+ assert!(!hub.0.lock().unwrap().contains_key("alpha:board-b"));
199219
200- hub.leave("board-a");
220+ hub.leave(&a, "board-a");
201221 assert!(
202- hub.0.lock().unwrap().contains_key("board-a"),
222+ hub.0.lock().unwrap().contains_key("alpha:board-a"),
203223 "one socket of two out keeps the room"
204224 );
205- hub.leave("board-a");
225+ hub.leave(&a, "board-a");
206226 assert!(
207227 hub.0.lock().unwrap().is_empty(),
208228 "the last socket out must drop the entry, or the map leaks"
209229 );
210230 }
211231
232+ /// Record keys are unique per database, so two schools routinely hold the
233+ /// same board key. One process serves both — nothing may cross.
234+ #[tokio::test]
235+ async fn a_stroke_never_crosses_into_another_school() {
236+ let (a, b) = (slug("alpha"), slug("beta"));
237+ let hub = BoardHub::default();
238+ let mut in_a = hub.subscribe(&a, "board-1");
239+ let mut in_b = hub.subscribe(&b, "board-1");
240+
241+ hub.publish(&a, "board-1", "alpha stroke".to_string());
242+ assert_eq!(in_a.recv().await.expect("alpha's own stroke"), "alpha stroke");
243+ assert!(
244+ in_b.try_recv().is_err(),
245+ "beta's board must not hear alpha's stroke"
246+ );
247+
248+ // And the rooms are counted apart: alpha's last socket out leaves
249+ // beta's room standing.
250+ hub.leave(&a, "board-1");
251+ let boards = hub.0.lock().unwrap();
252+ assert!(!boards.contains_key("alpha:board-1"));
253+ assert!(boards.contains_key("beta:board-1"));
254+ }
255+
212256 #[tokio::test]
213257 async fn only_the_last_socket_out_is_a_real_exit() {
258+ let a = slug("alpha");
214259 let presence = ExamPresence::default();
215- presence.enter("attempt-a");
216- presence.enter("attempt-a");
260+ presence.enter(&a, "attempt-a");
261+ presence.enter(&a, "attempt-a");
217262 assert!(
218- !presence.leave("attempt-a"),
263+ !presence.leave(&a, "attempt-a"),
219264 "one tab of two is not an exit"
220265 );
221- assert!(presence.leave("attempt-a"), "the last tab out is");
266+ assert!(presence.leave(&a, "attempt-a"), "the last tab out is");
222267 // Rooms are independent, and a fresh key starts over.
223- presence.enter("attempt-b");
224- presence.enter("attempt-a");
225- assert!(presence.leave("attempt-b"));
226- assert!(presence.leave("attempt-a"));
268+ presence.enter(&a, "attempt-b");
269+ presence.enter(&a, "attempt-a");
270+ assert!(presence.leave(&a, "attempt-b"));
271+ assert!(presence.leave(&a, "attempt-a"));
227272 // Unbalanced leaves degrade to "really left", never to a stuck room.
228- assert!(presence.leave("attempt-a"));
273+ assert!(presence.leave(&a, "attempt-a"));
274+ }
275+
276+ /// Two schools sitting the same attempt key count separately — otherwise
277+ /// one school's second tab would hold the other school's room open, and
278+ /// its walk-out would go unstamped.
279+ #[tokio::test]
280+ async fn presence_counts_are_per_school() {
281+ let (a, b) = (slug("alpha"), slug("beta"));
282+ let presence = ExamPresence::default();
283+ presence.enter(&a, "attempt-1");
284+ presence.enter(&b, "attempt-1");
285+ assert!(
286+ presence.leave(&a, "attempt-1"),
287+ "alpha's only socket out is alpha's exit, whatever beta is doing"
288+ );
289+ assert!(presence.leave(&b, "attempt-1"));
290+ assert!(presence.0.lock().unwrap().is_empty());
229291 }
230292 }
src/web/board_ws.rsmodified+12 -7
@@ -58,7 +58,7 @@
5858 use std::collections::VecDeque;
5959 use std::time::Duration;
6060
61-use crate::web::tenant_state::State;
61+use crate::web::tenant_state::{SchoolSlug, State};
6262 use axum::extract::Path;
6363 use axum::extract::ws::{Message, WebSocket, WebSocketUpgrade};
6464 use axum::response::Response;
@@ -75,6 +75,7 @@ use crate::domain::timestamp::Timestamp;
7575 use crate::domain::user::{User, UserId};
7676 use crate::error::AppError;
7777 use crate::state::AppState;
78+use crate::tenant::Slug;
7879 use crate::web::CurrentUser;
7980 use crate::web::room::{self, Incoming, RoomClosed, send, with_client_seq};
8081
@@ -118,6 +119,7 @@ enum ClientMessage {
118119 /// every action already re-reads through.
119120 pub async fn board_ws(
120121 State(st): State<AppState>,
122+ SchoolSlug(slug): SchoolSlug,
121123 CurrentUser(user): CurrentUser,
122124 Path(id): Path<String>,
123125 ws: WebSocketUpgrade,
@@ -136,18 +138,18 @@ pub async fn board_ws(
136138 }
137139 let board_id = board.get_id().clone();
138140 let user_id = user.get_id().clone();
139- Ok(ws.on_upgrade(move |socket| room(socket, st, board_id, user_id)))
141+ Ok(ws.on_upgrade(move |socket| room(socket, st, slug, board_id, user_id)))
140142 }
141143
142144 /// The room loop: the board's frames out, draw/clear/lock/ping in, until the
143145 /// socket closes or the board ends (closed, deleted, or the caller taken off
144146 /// it).
145-async fn room(mut socket: WebSocket, st: AppState, board: BoardId, user: UserId) {
147+async fn room(mut socket: WebSocket, st: AppState, slug: Slug, board: BoardId, user: UserId) {
146148 // Subscribe *before* anything is read out of the database: a stroke that
147149 // lands between a replay's read and this subscribe would otherwise be lost
148150 // outright, whereas one delivered twice is deduplicated by its id at the
149151 // client (which a resync forces anyway).
150- let mut feed = st.board_hub.subscribe(board.key());
152+ let mut feed = st.board_hub.subscribe(&slug, board.key());
151153 // The ids this socket drew, in the order they were published. The hub has
152154 // no idea who is listening, so the room filters its own strokes back out
153155 // here — a client that had to ignore the echo of every mark it just drew
@@ -176,7 +178,7 @@ async fn room(mut socket: WebSocket, st: AppState, board: BoardId, user: UserId)
176178 },
177179 incoming = socket.recv() => match room::classify(incoming) {
178180 Incoming::Text(text) => {
179- handle_message(&mut socket, text.as_str(), &board, &user, &mut mine, &st).await
181+ handle_message(&mut socket, text.as_str(), &slug, &board, &user, &mut mine, &st).await
180182 }
181183 Incoming::Gone => Err(RoomClosed),
182184 Incoming::Ignore => Ok(()),
@@ -187,7 +189,7 @@ async fn room(mut socket: WebSocket, st: AppState, board: BoardId, user: UserId)
187189 }
188190 }
189191 room::close(&mut socket).await;
190- st.board_hub.leave(board.key());
192+ st.board_hub.leave(&slug, board.key());
191193 }
192194
193195 type Step = Result<(), RoomClosed>;
@@ -395,6 +397,7 @@ fn stroke_body(stroke: &BoardStroke) -> Value {
395397 async fn handle_message(
396398 socket: &mut WebSocket,
397399 text: &str,
400+ slug: &Slug,
398401 board: &BoardId,
399402 user: &UserId,
400403 mine: &mut VecDeque<String>,
@@ -468,7 +471,7 @@ async fn handle_message(
468471 fanned["type"] = json!("stroke");
469472 fanned["epoch"] = json!(stroke.get_epoch());
470473 mine.push_back(stroke.get_id().key().to_string());
471- st.board_hub.publish(board.key(), fanned.to_string());
474+ st.board_hub.publish(slug, board.key(), fanned.to_string());
472475 let mut frame = json!({ "type": "saved", "id": stroke.get_id().key() });
473476 with_client_seq(&mut frame, client_seq);
474477 send(socket, frame).await
@@ -491,6 +494,7 @@ async fn handle_message(
491494 // canvas is the next one. Same shape as `POST /boards/{id}/clear`.
492495 Ok(marker) => {
493496 st.board_hub.publish(
497+ slug,
494498 board.key(),
495499 json!({
496500 "type": "cleared",
@@ -509,6 +513,7 @@ async fn handle_message(
509513 Some(live) => match live.set_locked(locked, user, &st.db).await {
510514 Ok(_) => {
511515 st.board_hub.publish(
516+ slug,
512517 board.key(),
513518 json!({ "type": "locked", "locked": locked, "by": user.key() }).to_string(),
514519 );
src/web/boards.rsmodified+15 -6
@@ -18,7 +18,7 @@
1818 //! mid-session keeps drawing over an already-open socket until the room hears
1919 //! about it, so a roster change *must* fan out.
2020
21-use crate::web::tenant_state::State;
21+use crate::web::tenant_state::{SchoolSlug, State};
2222 use axum::Json;
2323 use axum::extract::{Path, Query};
2424 use axum::http::StatusCode;
@@ -41,6 +41,7 @@ use crate::domain::role::Role;
4141 use crate::domain::user::{User, UserId};
4242 use crate::error::{AppError, ErrorResponse, ValidationError};
4343 use crate::state::AppState;
44+use crate::tenant::Slug;
4445
4546 use super::courses::can_manage_course;
4647 use super::{CurrentUser, Page, PageParams, RequireStudent, paginate, set_or_clear};
@@ -161,8 +162,8 @@ async fn resolve_participants(
161162
162163 /// Push one frame to whoever is in the room right now. An empty room is the
163164 /// normal case, not a failure.
164-fn fan_out(st: &AppState, board: &BoardId, frame: serde_json::Value) {
165- st.board_hub.publish(board.key(), frame.to_string());
165+fn fan_out(st: &AppState, slug: &Slug, board: &BoardId, frame: serde_json::Value) {
166+ st.board_hub.publish(slug, board.key(), frame.to_string());
166167 }
167168
168169 /// The roster frame every path that changes the invite list must publish. A
@@ -537,6 +538,7 @@ struct UpdateBoard {
537538 )]
538539 async fn update_board(
539540 State(st): State<AppState>,
541+ SchoolSlug(slug): SchoolSlug,
540542 CurrentUser(user): CurrentUser,
541543 Path(id): Path<String>,
542544 Json(req): Json<UpdateBoard>,
@@ -561,12 +563,13 @@ async fn update_board(
561563 let participants =
562564 resolve_participants(participants, board.get_participants(), &st.db).await?;
563565 board = board.set_participants(participants, &st.db).await?;
564- fan_out(&st, board.get_id(), participants_frame(&board));
566+ fan_out(&st, &slug, board.get_id(), participants_frame(&board));
565567 }
566568 if let Some(locked) = req.locked {
567569 board = board.set_locked(locked, user.get_id(), &st.db).await?;
568570 fan_out(
569571 &st,
572+ &slug,
570573 board.get_id(),
571574 json!({"type": "locked", "locked": locked, "by": user.get_id().key()}),
572575 );
@@ -602,6 +605,7 @@ async fn update_board(
602605 )]
603606 async fn clear_board(
604607 State(st): State<AppState>,
608+ SchoolSlug(slug): SchoolSlug,
605609 CurrentUser(user): CurrentUser,
606610 Path(id): Path<String>,
607611 ) -> Result<(StatusCode, Json<StrokeResponse>), AppError> {
@@ -612,6 +616,7 @@ async fn clear_board(
612616 // next one.
613617 fan_out(
614618 &st,
619+ &slug,
615620 board.get_id(),
616621 json!({
617622 "type": "cleared",
@@ -642,6 +647,7 @@ async fn clear_board(
642647 )]
643648 async fn close_board(
644649 State(st): State<AppState>,
650+ SchoolSlug(slug): SchoolSlug,
645651 CurrentUser(user): CurrentUser,
646652 Path(id): Path<String>,
647653 ) -> Result<Json<BoardResponse>, AppError> {
@@ -650,6 +656,7 @@ async fn close_board(
650656 let board = board.close(&st.db).await?;
651657 fan_out(
652658 &st,
659+ &slug,
653660 board.get_id(),
654661 json!({
655662 "type": "closed",
@@ -812,6 +819,7 @@ impl InviteSource {
812819 )]
813820 async fn invite_board(
814821 State(st): State<AppState>,
822+ SchoolSlug(slug): SchoolSlug,
815823 CurrentUser(user): CurrentUser,
816824 Path(id): Path<String>,
817825 Json(req): Json<InviteSource>,
@@ -852,7 +860,7 @@ async fn invite_board(
852860 // branch that has to prove the two lists are equal, and a re-invite that
853861 // added nobody is the idempotent case, not the hot path.
854862 let board = board.set_participants(roster, &st.db).await?;
855- fan_out(&st, board.get_id(), participants_frame(&board));
863+ fan_out(&st, &slug, board.get_id(), participants_frame(&board));
856864 Ok(Json(BoardResponse::new(&board)))
857865 }
858866
@@ -875,6 +883,7 @@ async fn invite_board(
875883 )]
876884 async fn delete_board(
877885 State(st): State<AppState>,
886+ SchoolSlug(slug): SchoolSlug,
878887 CurrentUser(user): CurrentUser,
879888 Path(id): Path<String>,
880889 ) -> Result<StatusCode, AppError> {
@@ -884,7 +893,7 @@ async fn delete_board(
884893 board.delete(&st.db).await?;
885894 // Told after the row is gone: a room that acts on this and then re-reads
886895 // must find nothing, not a board about to disappear.
887- fan_out(&st, &id, json!({"type": "deleted"}));
896+ fan_out(&st, &slug, &id, json!({"type": "deleted"}));
888897 Ok(StatusCode::NO_CONTENT)
889898 }
890899
src/web/chatbot.rsmodified+5 -3
@@ -20,7 +20,7 @@
2020
2121 use std::time::Duration;
2222
23-use crate::web::tenant_state::State;
23+use crate::web::tenant_state::{SchoolSlug, State};
2424 use axum::Json;
2525 use axum::extract::{Path, Query};
2626 use axum::http::StatusCode;
@@ -49,7 +49,7 @@ use crate::domain::role::Role;
4949 use crate::domain::settings::Settings;
5050 use crate::domain::user::UserId;
5151 use crate::error::{AppError, ErrorResponse, ValidationError};
52-use crate::state::AppState;
52+use crate::state::{AppState, scoped_key};
5353
5454 use super::{CurrentUser, Page, PageParams};
5555
@@ -377,12 +377,14 @@ async fn list_messages(
377377 )]
378378 async fn send_message(
379379 State(st): State<AppState>,
380+ SchoolSlug(slug): SchoolSlug,
380381 CurrentUser(user): CurrentUser,
381382 Path(id): Path<String>,
382383 Json(req): Json<SendChatbotMessage>,
383384 ) -> Result<Response, AppError> {
384385 // Charged first: a rejected turn must cost nothing and leave no row.
385- st.chatbot_limit.enforce_user(user.get_id().key())?;
386+ st.chatbot_limit
387+ .enforce_user(&scoped_key(&slug, user.get_id().key()))?;
386388
387389 let thread = own_thread(&id, user.get_id(), &st.db).await?;
388390 let settings = Settings::load(&st.db).await?;
src/web/exam_ws.rsmodified+14 -5
@@ -56,7 +56,7 @@
5656
5757 use std::time::Duration;
5858
59-use crate::web::tenant_state::State;
59+use crate::web::tenant_state::{SchoolSlug, State};
6060 use axum::extract::Path;
6161 use axum::extract::ws::{WebSocket, WebSocketUpgrade};
6262 use axum::response::Response;
@@ -73,6 +73,7 @@ use crate::domain::timestamp::Timestamp;
7373 use crate::domain::user::UserId;
7474 use crate::error::AppError;
7575 use crate::state::AppState;
76+use crate::tenant::Slug;
7677 use crate::validate::validate_required;
7778 use crate::web::CurrentUser;
7879 use crate::web::exams::{
@@ -138,6 +139,7 @@ enum ClientMessage {
138139 /// dying socket's teardown stamp a student who was already reconnecting.
139140 pub async fn attempt_ws(
140141 State(st): State<AppState>,
142+ SchoolSlug(slug): SchoolSlug,
141143 CurrentUser(user): CurrentUser,
142144 Path(id): Path<String>,
143145 ws: WebSocketUpgrade,
@@ -153,13 +155,20 @@ pub async fn attempt_ws(
153155 course_of(&exam, &st.db).await?.require_open(&st.db).await?;
154156
155157 let user_id = user.get_id().clone();
156- Ok(ws.on_upgrade(move |socket| room(socket, st, exam, attempt, user_id)))
158+ Ok(ws.on_upgrade(move |socket| room(socket, st, slug, exam, attempt, user_id)))
157159 }
158160
159161 /// The room loop: state ticks out, answer/finish/ping in, until the socket
160162 /// closes or the room's sitting reaches a terminal state. The room is bound
161163 /// to the attempt it was opened for — `attempt` — and to no later sitting.
162-async fn room(mut socket: WebSocket, st: AppState, exam: Exam, attempt: ExamAttempt, user: UserId) {
164+async fn room(
165+ mut socket: WebSocket,
166+ st: AppState,
167+ slug: Slug,
168+ exam: Exam,
169+ attempt: ExamAttempt,
170+ user: UserId,
171+) {
163172 let exam_id = exam.get_id().clone();
164173 let attempt_id = attempt.get_id().clone();
165174 // Join critical section: this socket counts as presence in the sitting's
@@ -171,7 +180,7 @@ async fn room(mut socket: WebSocket, st: AppState, exam: Exam, attempt: ExamAtte
171180 // failed clear leaves the stamp for the next join or the teacher's door.
172181 {
173182 let _guard = PRESENCE_LOCK.lock().await;
174- st.exam_presence.enter(attempt_id.key());
183+ st.exam_presence.enter(&slug, attempt_id.key());
175184 if let Err(err) = attempt.set_left(None, &st.db).await {
176185 tracing::warn!("exam room could not clear left_at on join: {err}");
177186 }
@@ -211,7 +220,7 @@ async fn room(mut socket: WebSocket, st: AppState, exam: Exam, attempt: ExamAtte
211220 // superseded by a retake is terminal) need no stamp. Best-effort: a
212221 // failed stamp only means it goes unrecorded.
213222 let _guard = PRESENCE_LOCK.lock().await;
214- if st.exam_presence.leave(attempt_id.key()) {
223+ if st.exam_presence.leave(&slug, attempt_id.key()) {
215224 stamp_left(&exam_id, &attempt_id, &st.db).await;
216225 }
217226 }
src/web/users.rsmodified+4 -1
@@ -1,4 +1,4 @@
1-use crate::web::tenant_state::State;
1+use crate::web::tenant_state::{SchoolSlug, State};
22 use axum::Json;
33 use axum::extract::{DefaultBodyLimit, Multipart, Path, Query};
44 use axum::http::StatusCode;
@@ -463,6 +463,7 @@ async fn update_user_preferences(
463463 )]
464464 async fn set_role(
465465 State(st): State<AppState>,
466+ SchoolSlug(slug): SchoolSlug,
466467 RequireAdmin(admin): RequireAdmin,
467468 Path(id): Path<String>,
468469 Json(req): Json<SetRole>,
@@ -490,6 +491,7 @@ async fn set_role(
490491 // stroke came back refused.
491492 for board in boards {
492493 st.board_hub.publish(
494+ &slug,
493495 board.get_id().key(),
494496 json!({
495497 "type": "participants",
@@ -504,6 +506,7 @@ async fn set_role(
504506 );
505507 if let Some(closed_at) = board.get_closed_at() {
506508 st.board_hub.publish(
509+ &slug,
507510 board.get_id().key(),
508511 json!({"type": "closed", "closed_at": closed_at.as_millis()}).to_string(),
509512 );