Manager-assigned course teachers
Browse files at this commit5ff771b632757a16cbf1c8791ae917022f45bedeParent: bdde827- feat
- manager-assigned course teachers
14 changed files +703 -130
- README.md +38 -14
- src/database.rs +6 -0
- src/domain/course.rs +94 -3
- src/lib.rs +3 -3
- src/web/attendance.rs +2 -2
- src/web/courses.rs +154 -39
- src/web/dto.rs +18 -1
- src/web/exams.rs +32 -32
- src/web/marks.rs +2 -2
- src/web/mod.rs +8 -6
- src/web/sessions.rs +6 -6
- src/web/subjects.rs +8 -7
- src/web/users.rs +9 -1
- tests/integration.rs +323 -14
README.mdmodified+38 -14
| @@ -29,7 +29,11 @@ full — lays out its **subjects** (curriculum topics — | ||
| 29 | 29 | every exam question must be tagged with one of its course's subjects, so |
| 30 | 30 | results can later be read per topic), enrolls students, adds |
| 31 | 31 | exams inside it, and grades — enrolling, sitting exams, roll call, and marks are |
| 32 | -all student-only, staff never take part; students read a per-course weighted average and | |
| 32 | +all student-only, staff never take part. A course is run by whoever created it | |
| 33 | +plus any teachers a **manager assigns** to it (`POST /courses/{id}/teachers`): | |
| 34 | +an assigned teacher manages everything inside the course — exams, sessions, | |
| 35 | +subjects, roster, grading — but can't delete it or change who else teaches it, | |
| 36 | +and a demotion below `teacher` sweeps their assignments away. Students read a per-course weighted average and | |
| 33 | 37 | an overall average from their mark report — each exam weighted by its **kind** |
| 34 | 38 | (midterms can count double, orals once: weights are set per kind in settings, |
| 35 | 39 | not per exam). Exams run **sync** (one |
| @@ -251,9 +255,9 @@ course enrollments. | ||
| 251 | 255 | | Register users onto a registration event | teacher | Teachers place **students** (students never register themselves) and take a seat for **themselves** — never for another staff member. Unregistering mirrors the same rule | |
| 252 | 256 | | List an event's attendance or its roster report | teacher | Students read their own tallies via the attendance report | |
| 253 | 257 | | Edit / delete an event | teacher | Only the **creator**, or a `manager`+ for any event | |
| 254 | -| View a course's sessions | student | Only inside **visible** courses: enrolled, creator, or `manager`+ | | |
| 258 | +| View a course's sessions | student | Only inside **visible** courses: enrolled, creator, assigned teacher, or `manager`+ | | |
| 255 | 259 | | List a session's roll call | teacher | The **session's teacher**, or anyone with course-management rights | |
| 256 | -| Create / edit / delete a course session | teacher | Course-management rights (course creator, or `manager`+) | | |
| 260 | +| Create / edit / delete a course session | teacher | Course-management rights (course creator, an assigned teacher, or `manager`+) | | |
| 257 | 261 | | Take a session's roll call (mark/remove **enrolled students**) | teacher | The **session's teacher**, or anyone with course-management rights; only students sit on a roster | |
| 258 | 262 | | Mark / remove the **session teacher's** presence row | manager | Staff presence is management's call — the teacher can't self-mark | |
| 259 | 263 | | Work check-in / check-out; view **own** work log | teacher | Instants are server-stamped, never client-supplied | |
| @@ -265,14 +269,16 @@ course enrollments. | ||
| 265 | 269 | | Approve a pending pool question; delete any question or solution | teacher | Approval publishes school-wide and **freezes** the content; rejection = deletion — moderation never edits, so teacher+ cannot rewrite a solution | |
| 266 | 270 | | Read **own** attendance report | student | | |
| 267 | 271 | | Read another user's attendance report | teacher | Narrowed to the caller's managed courses; `manager`+ sees all; a `parent` sees a linked student's in full | |
| 268 | -| View **visible** courses/exams and a course's subjects; read **own** result, courses, mark report | student | Visible = enrolled (teachers: + created; `manager`+: all); exam **drafts** show only to the course's managers | | |
| 272 | +| View **visible** courses/exams and a course's subjects; read **own** result, courses, mark report | student | Visible = enrolled (teachers: + created + assigned; `manager`+: all); exam **drafts** show only to the course's managers | | |
| 269 | 273 | | Sit a sittable exam (`sync`/`async`/`open`): start / resume / retake / read / submit **own** attempt | student | **Students only** — staff never sit; must be enrolled; window (where one exists) and `max_attempts` enforced by the server | |
| 270 | 274 | | Answer questions inside **own** attempt (REST autosave or the exam-room WebSocket) | student | **Students only**; attempt must be `in_progress`; deadline judged by the server clock; blocked after leaving the room while `allow_rejoin` is off | |
| 271 | 275 | | Author an exam's questions (add/edit/delete, incl. question + option images) | teacher | Course-management rights; frozen once anyone has an attempt | |
| 272 | 276 | | Read a question list (with `correct`) or a student's answer sheet | teacher | Course-management rights — one teacher can't read another's answer key | |
| 273 | 277 | | Watch an exam's live monitor (snapshot or SSE stream) | teacher | Course-management rights | |
| 274 | -| Create courses | teacher | The creator manages the course | | |
| 275 | -| Manage inside a course: edit/delete it, enroll/unenroll **students**, add/edit/delete its exams and **subjects**, grade, remove results | teacher | Only the **course creator**, or a `manager`+ for any course; only students can be enrolled; a subject still referenced by exam questions won't delete (`409`) | | |
| 278 | +| Create courses | teacher | The creator manages the course, and owns it for good | | |
| 279 | +| Assign / unassign a course's teachers | manager | Staffing is the office's call — a course's own creator cannot hand rights to peers; the assignee must be `teacher`+ | | |
| 280 | +| Delete a course | teacher | Only the **creator**, or a `manager`+ — an assigned teacher runs the course but doesn't own it | | |
| 281 | +| Manage inside a course: edit it, enroll/unenroll **students**, add/edit/delete its exams and **subjects**, grade, remove results | teacher | The **course creator**, a teacher **assigned** to it, or a `manager`+ for any course; only students can be enrolled; a subject still referenced by exam questions won't delete (`409`) | | |
| 276 | 282 | | View a course's roster, an exam's result list / statistics | teacher | Course-management rights | |
| 277 | 283 | | Read another user's mark report | teacher | Narrowed to the caller's managed courses; `manager`+ sees all; a `parent` sees a linked student's in full | |
| 278 | 284 | | Grade students | teacher | Target must be an **enrolled student**; grading never targets oneself | |
| @@ -327,13 +333,29 @@ roster reaches it, new enrolls are refused with `409` (members already on the | ||
| 327 | 333 | roster are unaffected, even if the cap is later lowered below them; `null` |
| 328 | 334 | lifts the cap). |
| 329 | 335 | |
| 336 | +**Who runs a course.** Its **creator** owns it for good — only they (or a | |
| 337 | +manager+) may delete it. On top of that, a manager can **assign** any | |
| 338 | +`teacher`+ to the course with `POST /courses/{id}/teachers` (`{user_id}`, | |
| 339 | +idempotent) and drop them again with `DELETE /courses/{id}/teachers/{user}`. | |
| 340 | +An assigned teacher gets full **course-management rights** — edit the course, | |
| 341 | +enroll and unenroll students, add exams, sessions and subjects, grade, take | |
| 342 | +roll call — but *not* the two owner powers: they cannot delete the course, and | |
| 343 | +they cannot change who else teaches it. Staffing is deliberately the office's | |
| 344 | +call, so a course's own creator cannot hand rights to their peers; only | |
| 345 | +manager+ may touch the list. Every course response carries its `teachers` | |
| 346 | +array alongside `creator`, and a user demoted below `teacher` is swept off | |
| 347 | +every course they were assigned to (the mirror of promotion dropping | |
| 348 | +enrollments). | |
| 349 | + | |
| 330 | 350 | Course data is walled per course. A course, its exams, its sessions, and its |
| 331 | 351 | subjects are |
| 332 | -**visible** only to its enrolled users, its creator, and manager+ — a student | |
| 352 | +**visible** only to its enrolled users, its creator, its assigned teachers, | |
| 353 | +and manager+ — a student | |
| 333 | 354 | sees just the classes they were added to, and the `/courses` / `/exams` |
| 334 | 355 | catalogs are filtered accordingly. Teacher-level reads *inside* a course |
| 335 | 356 | (roster, results, statistics, the question list, answer sheets, the live |
| 336 | -monitor) additionally need **course-management rights** (creator or manager+): | |
| 357 | +monitor) additionally need **course-management rights** (creator, an assigned | |
| 358 | +teacher, or manager+): | |
| 337 | 359 | one teacher cannot look into another teacher's course, and the per-user |
| 338 | 360 | marks/attendance reports narrow to the courses the caller manages. |
| 339 | 361 | |
| @@ -400,16 +422,18 @@ their existing shapes: the student exam-room reads | ||
| 400 | 422 | | POST | `/courses` | teacher | `{title, description?, kind?, term_id?, capacity?}` — `kind` is `course` (default), `study` (etüt), or `club` (kulüp); `capacity` caps the roster (creator manages it) | |
| 401 | 423 | | GET | `/courses` | student | The caller's visible courses: created + enrolled (manager+: all) · paged | |
| 402 | 424 | | GET | `/courses/me` | student | The caller's **enrolled** courses · paged | |
| 403 | -| GET | `/courses/{id}` | student | Get course (enrolled, creator, or manager+) | | |
| 404 | -| PATCH | `/courses/{id}` | teacher | Edit course incl. `kind` and `capacity` (`null` lifts the cap) (creator, or manager+ for any) | | |
| 405 | -| DELETE | `/courses/{id}` | teacher | Delete course + its exams, results, enrollments, subjects (creator, or manager+) | | |
| 425 | +| GET | `/courses/{id}` | student | Get course (enrolled, creator, assigned teacher, or manager+) | | |
| 426 | +| PATCH | `/courses/{id}` | teacher | Edit course incl. `kind` and `capacity` (`null` lifts the cap) (course manager) | | |
| 427 | +| DELETE | `/courses/{id}` | teacher | Delete course + its exams, results, enrollments, subjects (creator, or manager+ — **not** an assigned teacher) | | |
| 428 | +| POST | `/courses/{id}/teachers` | manager | `{user_id}` — assign a **teacher+** to run the course (idempotent; returns the course) | | |
| 429 | +| DELETE | `/courses/{id}/teachers/{user}` | manager | Unassign a teacher (`404` if they weren't assigned) | | |
| 406 | 430 | | POST | `/courses/{id}/enrollments` | teacher | `{user_id}` — enroll a **student** (idempotent upsert; course manager; only students can be enrolled; `409` once a capped course is full) | |
| 407 | 431 | | GET | `/courses/{id}/enrollments` | teacher | List the course roster (course manager) · paged | |
| 408 | 432 | | DELETE | `/courses/{id}/enrollments/{user}` | teacher | Unenroll (keeps recorded results; course manager) | |
| 409 | 433 | | POST | `/courses/{id}/sessions` | teacher | `{topic?, teacher_id?, starts_at, ends_at?}` — add a lesson (course manager; teacher defaults to the caller) | |
| 410 | -| GET | `/courses/{id}/sessions` | student | List the course's sessions, most recent first (enrolled, creator, or manager+) · paged | | |
| 434 | +| GET | `/courses/{id}/sessions` | student | List the course's sessions, most recent first (enrolled, creator, assigned teacher, or manager+) · paged | | |
| 411 | 435 | | POST | `/courses/{id}/subjects` | teacher | `{name, description?}` — add a curriculum subject (course manager) | |
| 412 | -| GET | `/courses/{id}/subjects` | student | List the course's subjects, creation order (enrolled, creator, or manager+) · paged | | |
| 436 | +| GET | `/courses/{id}/subjects` | student | List the course's subjects, creation order (enrolled, creator, assigned teacher, or manager+) · paged | | |
| 413 | 437 | | GET | `/subjects/{id}` | student | Get subject (enrolled, creator, or manager+) | |
| 414 | 438 | | PATCH | `/subjects/{id}` | teacher | Edit a subject's name/description (course manager; its course is fixed) | |
| 415 | 439 | | DELETE | `/subjects/{id}` | teacher | Delete a subject (course manager); `409` while exam questions reference it | |
| @@ -420,7 +444,7 @@ their existing shapes: the student exam-room reads | ||
| 420 | 444 | | GET | `/sessions/{id}/attendance` | teacher | List the session's roll call (session teacher or course manager) · paged | |
| 421 | 445 | | DELETE | `/sessions/{id}/attendance/{user}` | teacher | Remove a roll-call row (same rights as marking) | |
| 422 | 446 | | POST | `/courses/{id}/exams` | teacher | `{title, description?, kind, mode?, starts_at?, ends_at?, duration_ms?, max_attempts?, allow_rejoin?, draft?}` — add an exam (course manager); its weight comes from the kind; `draft: true` keeps it hidden while it's written | |
| 423 | -| GET | `/courses/{id}/exams` | student | List the course's exams (enrolled, creator, or manager+; drafts appear to course managers only) · paged | | |
| 447 | +| GET | `/courses/{id}/exams` | student | List the course's exams (enrolled, creator, assigned teacher, or manager+; drafts appear to course managers only) · paged | | |
| 424 | 448 | | GET | `/exams` | student | The caller's visible exams: their courses' (manager+: all; drafts of managed courses only) · paged | |
| 425 | 449 | | GET | `/exams/{id}` | student | Get exam (enrolled, creator, or manager+; a draft is a `404` for everyone but its course's managers) | |
| 426 | 450 | | PATCH | `/exams/{id}` | teacher | Edit exam incl. `kind` (re-weights it), schedule, `max_attempts`, `allow_rejoin`, `draft` (course manager; `course` immutable, `mode` frozen once attempted, re-drafting frozen once attempts/results exist — the rest stays live) | |
src/database.rsmodified+6 -0
| @@ -126,6 +126,8 @@ const MIGRATION: &str = " | ||
| 126 | 126 | |
| 127 | 127 | DEFINE TABLE IF NOT EXISTS course SCHEMAFULL; |
| 128 | 128 | DEFINE FIELD IF NOT EXISTS creator ON course TYPE record<user>; |
| 129 | + DEFINE FIELD IF NOT EXISTS teachers ON course TYPE array<record<user>> DEFAULT []; | |
| 130 | + DEFINE FIELD IF NOT EXISTS teachers[*] ON course TYPE record<user>; | |
| 129 | 131 | DEFINE FIELD IF NOT EXISTS title ON course TYPE string; |
| 130 | 132 | DEFINE FIELD IF NOT EXISTS description ON course TYPE string; |
| 131 | 133 | DEFINE FIELD IF NOT EXISTS kind ON course TYPE string DEFAULT 'course'; |
| @@ -291,6 +293,10 @@ const BACKFILL: &str = " | ||
| 291 | 293 | |
| 292 | 294 | UPDATE course SET kind = 'course' WHERE kind = NONE; |
| 293 | 295 | |
| 296 | + -- Courses predate assignable teachers (2026-07-21): every existing course | |
| 297 | + -- was run by its creator alone, so it starts with nobody else assigned. | |
| 298 | + UPDATE course SET teachers = [] WHERE teachers = NONE; | |
| 299 | + | |
| 294 | 300 | -- Exams predate the draft flag (2026-07-19): everything already out there |
| 295 | 301 | -- was live for its course, so it stays published. |
| 296 | 302 | UPDATE exam SET draft = false WHERE draft = NONE; |
src/domain/course.rsmodified+94 -3
| @@ -88,10 +88,17 @@ impl CourseKind { | ||
| 88 | 88 | /// `study` (etüt), and `club` (kulüp). An optional `capacity` caps the roster |
| 89 | 89 | /// at enroll time (`None` = unlimited); rows written before the field existed |
| 90 | 90 | /// decode as uncapped. |
| 91 | +/// | |
| 92 | +/// `creator` owns the course for good — only they (or a manager+) may delete | |
| 93 | +/// it. `teachers` are the staff a manager assigned to run it: full management | |
| 94 | +/// rights inside the course, no power to delete it or change the assignment | |
| 95 | +/// list. Rows written before the field existed decode with nobody assigned. | |
| 91 | 96 | #[derive(Debug, Clone, SurrealValue)] |
| 92 | 97 | pub struct Course { |
| 93 | 98 | id: CourseId, |
| 94 | 99 | creator: UserId, |
| 100 | + #[surreal(default)] | |
| 101 | + teachers: Vec<UserId>, | |
| 95 | 102 | title: CourseTitle, |
| 96 | 103 | description: CourseDescription, |
| 97 | 104 | kind: CourseKind, |
| @@ -133,6 +140,17 @@ impl Course { | ||
| 133 | 140 | &self.creator == user |
| 134 | 141 | } |
| 135 | 142 | |
| 143 | + /// The staff assigned to run this course, in assignment order. | |
| 144 | + pub fn get_teachers(&self) -> &[UserId] { | |
| 145 | + &self.teachers | |
| 146 | + } | |
| 147 | + | |
| 148 | + /// Whether `user` was assigned to teach this course. Says nothing about | |
| 149 | + /// the creator — they own it whether or not they also appear here. | |
| 150 | + pub fn is_assigned(&self, user: &UserId) -> bool { | |
| 151 | + self.teachers.contains(user) | |
| 152 | + } | |
| 153 | + | |
| 136 | 154 | pub async fn create( |
| 137 | 155 | creator: &UserId, |
| 138 | 156 | title: CourseTitle, |
| @@ -145,6 +163,7 @@ impl Course { | ||
| 145 | 163 | let course = Course { |
| 146 | 164 | id: CourseId::generate(), |
| 147 | 165 | creator: creator.clone(), |
| 166 | + teachers: Vec::new(), | |
| 148 | 167 | title, |
| 149 | 168 | description, |
| 150 | 169 | kind, |
| @@ -182,10 +201,11 @@ impl Course { | ||
| 182 | 201 | Ok(result.take::<Vec<Course>>(0)?) |
| 183 | 202 | } |
| 184 | 203 | |
| 185 | - /// The courses `user` created — a teacher's slice of the catalog. | |
| 186 | - pub async fn list_created(user: &UserId, db: &Database) -> Result<Vec<Course>, AppError> { | |
| 204 | + /// The courses `user` runs — the ones they created plus the ones a manager | |
| 205 | + /// assigned them to. A teacher's slice of the catalog. | |
| 206 | + pub async fn list_for_teacher(user: &UserId, db: &Database) -> Result<Vec<Course>, AppError> { | |
| 187 | 207 | let mut result = db |
| 188 | - .query("SELECT * FROM course WHERE creator = $usr ORDER BY id DESC") | |
| 208 | + .query("SELECT * FROM course WHERE creator = $usr OR $usr IN teachers ORDER BY id DESC") | |
| 189 | 209 | .bind(("usr", user.record())) |
| 190 | 210 | .await? |
| 191 | 211 | .check()?; |
| @@ -225,6 +245,46 @@ impl Course { | ||
| 225 | 245 | updated.ok_or(AppError::NotFound) |
| 226 | 246 | } |
| 227 | 247 | |
| 248 | + /// Assign `teacher` to run this course, or return the course untouched if | |
| 249 | + /// they already run it — assignment is idempotent, like enrollment. | |
| 250 | + pub async fn assign_teacher( | |
| 251 | + mut self, | |
| 252 | + teacher: &UserId, | |
| 253 | + db: &Database, | |
| 254 | + ) -> Result<Course, AppError> { | |
| 255 | + if self.is_assigned(teacher) { | |
| 256 | + return Ok(self); | |
| 257 | + } | |
| 258 | + self.teachers.push(teacher.clone()); | |
| 259 | + let updated: Option<Course> = db.update(self.id.record()).content(self).await?; | |
| 260 | + updated.ok_or(AppError::NotFound) | |
| 261 | + } | |
| 262 | + | |
| 263 | + /// Drop `teacher` from this course. `None` when they weren't assigned, so | |
| 264 | + /// the web layer can answer 404 instead of pretending it removed someone. | |
| 265 | + pub async fn unassign_teacher( | |
| 266 | + mut self, | |
| 267 | + teacher: &UserId, | |
| 268 | + db: &Database, | |
| 269 | + ) -> Result<Option<Course>, AppError> { | |
| 270 | + if !self.is_assigned(teacher) { | |
| 271 | + return Ok(None); | |
| 272 | + } | |
| 273 | + self.teachers.retain(|assigned| assigned != teacher); | |
| 274 | + let updated: Option<Course> = db.update(self.id.record()).content(self).await?; | |
| 275 | + updated.map(Some).ok_or(AppError::NotFound) | |
| 276 | + } | |
| 277 | + | |
| 278 | + /// Strip `user` from every course they were assigned to — the sweep for a | |
| 279 | + /// user demoted below `teacher`, who may no longer run anything. | |
| 280 | + pub async fn unassign_everywhere(user: &UserId, db: &Database) -> Result<(), AppError> { | |
| 281 | + db.query("UPDATE course SET teachers -= $usr WHERE $usr IN teachers") | |
| 282 | + .bind(("usr", user.record())) | |
| 283 | + .await? | |
| 284 | + .check()?; | |
| 285 | + Ok(()) | |
| 286 | + } | |
| 287 | + | |
| 228 | 288 | /// Delete the course and cascade-remove everything inside it: results, |
| 229 | 289 | /// attempts, and question images of its exams, its enrollments, its |
| 230 | 290 | /// sessions with their roll call, its subjects, and the exams themselves. |
| @@ -289,6 +349,7 @@ mod tests { | ||
| 289 | 349 | let course = Course { |
| 290 | 350 | id: CourseId::generate(), |
| 291 | 351 | creator: UserId::from_key("01J8XZ0K3Q8G7X2M4N5P6R7S8T"), |
| 352 | + teachers: Vec::new(), | |
| 292 | 353 | title: CourseTitle::try_new("chess").unwrap(), |
| 293 | 354 | description: CourseDescription::try_new("").unwrap(), |
| 294 | 355 | kind: CourseKind::try_new("club").unwrap(), |
| @@ -302,4 +363,34 @@ mod tests { | ||
| 302 | 363 | let decoded = Course::from_value(Value::Object(object)).unwrap(); |
| 303 | 364 | assert_eq!(decoded.get_capacity(), None); |
| 304 | 365 | } |
| 366 | + | |
| 367 | + /// Every course row written before teacher assignment existed has no | |
| 368 | + /// `teachers` key. The boot backfill fills them in, but a row read before | |
| 369 | + /// that lands must still decode — as a course nobody was assigned to, | |
| 370 | + /// never as a decode error that 500s the catalog. | |
| 371 | + #[tokio::test] | |
| 372 | + async fn course_decodes_without_teachers_key() { | |
| 373 | + use surrealdb::types::Value; | |
| 374 | + | |
| 375 | + let assigned = UserId::from_key("01J8XZ0K3Q8G7X2M4N5P6R7S8U"); | |
| 376 | + let course = Course { | |
| 377 | + id: CourseId::generate(), | |
| 378 | + creator: UserId::from_key("01J8XZ0K3Q8G7X2M4N5P6R7S8T"), | |
| 379 | + teachers: vec![assigned.clone()], | |
| 380 | + title: CourseTitle::try_new("chess").unwrap(), | |
| 381 | + description: CourseDescription::try_new("").unwrap(), | |
| 382 | + kind: CourseKind::try_new("club").unwrap(), | |
| 383 | + term: None, | |
| 384 | + capacity: None, | |
| 385 | + }; | |
| 386 | + assert!(course.is_assigned(&assigned)); | |
| 387 | + | |
| 388 | + let Value::Object(mut object) = course.into_value() else { | |
| 389 | + panic!("course must encode as an object"); | |
| 390 | + }; | |
| 391 | + object.remove("teachers"); | |
| 392 | + let decoded = Course::from_value(Value::Object(object)).unwrap(); | |
| 393 | + assert!(decoded.get_teachers().is_empty()); | |
| 394 | + assert!(!decoded.is_assigned(&assigned)); | |
| 395 | + } | |
| 305 | 396 | } |
src/lib.rsmodified+3 -3
| @@ -34,7 +34,7 @@ use crate::state::AppState; | ||
| 34 | 34 | info( |
| 35 | 35 | title = "Hezarfen Backend API", |
| 36 | 36 | version = env!("CARGO_PKG_VERSION"), |
| 37 | - description = "Notes, events, attendance, courses, and weighted exam marks behind cookie-session auth. Notes carry file attachments (PDFs, documents — stored on disk, capped per file by the school's settings). Any two users can message each other one-to-one, mail-style: each side files its own copy through folders (recipient: inbox/archive/trash with a read flag the sender sees as a receipt; sender: sent/trash), and a message is truly gone only when both sides have deleted it from their trash. Exams run sync (one window), async (window + per-attempt duration), or open (sit anytime), with per-exam attempt limits (retakes) and a teacher-controlled rejoin door on the live exam room; questions can carry images — an illustration on any question, and per-option pictures on choice questions. Enrollment, exam-sitting, roll call, and marks are student-only — staff run them, they don't take part. Every event carries an audience — the whole school, one role, a course's enrollment, or a registration list — that defines its expected-attendee roster (visibility is unaffected: everyone sees every event). Registration-audience events hold a signup list built one seat at a time: teachers register students (students never register themselves), staff register only themselves, the list optionally caps at a capacity, and it closes the moment the event starts. Event attendance is taken by teachers+ against that audience (students never self-mark), and a per-event roster report joins the expected list with the marks to show who missed. Courses come in three behaviorally identical kinds — `course` (a regular class), `study` (a supervised study session — etüt), and `club` (a student club — kulüp) — may cap their roster with an optional enroll-time `capacity` (a full course refuses new members), and carry lesson sessions with teacher-taken roll call; each course also owns its curriculum as a list of subjects, and every exam question must be tagged with one of its course's subjects (a subject still referenced by questions cannot be deleted); staff clock in/out on a server-stamped work log; students run a pomodoro study timer whose focus sessions land in a server-stamped log (starting discards a dangling unfinished session; teachers can read any student's log and its total focus time); attendance reports tally events and per-course roll call with rates. School-varying policy (exam kinds with their course-average weights, attendance statuses, grade-display bands, the note-file size limit) lives in an editable settings singleton, and courses may link to academic terms. Each account also carries its own UI preferences — theme (`light`/`dark`) and language (`tr`/`en`) — self-managed, admin-editable for anyone, and `null` until chosen (the client then follows the device preference). A `parent` role observes without touching: admins tie any number of students to a parent account (`POST /users/{id}/students`), the parent lists them at `GET /users/me/students` and reads each one's mark, attendance, and pomodoro reports — and nothing else; parents hold no staff power and never act as students (no enrolling, sitting exams, or roll call). A school-wide **question pool** lets students ask for help: a student posts a question (optionally with a photo of the problem — same raster rules and size cap as question images), a teacher+ approves it into the pool (or deletes it — rejection is deletion, there is no rejected state), and every approved question is readable by the whole school (parents excepted), with anyone free to offer solutions under it — text plus an optional photo of the worked steps, both editable by the solution's author at any time, since solutions are unmoderated and never freeze — and every question row carries its `solution_count`; pending questions are visible only to their asker and to teacher+ (whose `?status=pending` list is the approval queue), and approval freezes the question's content so nothing unmoderated can slip into the pool afterwards. While the database connection is reconnecting (a restart, a dropped socket) requests briefly answer `503` with `Retry-After: 1` — transient, retry shortly. Every list endpoint accepts `?limit=&offset=` and returns a `{items, total, limit, offset}` page envelope — paging is opt-in, so omitting `limit` returns the full list and `total` always carries the unpaged count.", | |
| 37 | + description = "Notes, events, attendance, courses, and weighted exam marks behind cookie-session auth. Notes carry file attachments (PDFs, documents — stored on disk, capped per file by the school's settings). Any two users can message each other one-to-one, mail-style: each side files its own copy through folders (recipient: inbox/archive/trash with a read flag the sender sees as a receipt; sender: sent/trash), and a message is truly gone only when both sides have deleted it from their trash. Exams run sync (one window), async (window + per-attempt duration), or open (sit anytime), with per-exam attempt limits (retakes) and a teacher-controlled rejoin door on the live exam room; questions can carry images — an illustration on any question, and per-option pictures on choice questions. Enrollment, exam-sitting, roll call, and marks are student-only — staff run them, they don't take part. Every event carries an audience — the whole school, one role, a course's enrollment, or a registration list — that defines its expected-attendee roster (visibility is unaffected: everyone sees every event). Registration-audience events hold a signup list built one seat at a time: teachers register students (students never register themselves), staff register only themselves, the list optionally caps at a capacity, and it closes the moment the event starts. Event attendance is taken by teachers+ against that audience (students never self-mark), and a per-event roster report joins the expected list with the marks to show who missed. Courses come in three behaviorally identical kinds — `course` (a regular class), `study` (a supervised study session — etüt), and `club` (a student club — kulüp) — may cap their roster with an optional enroll-time `capacity` (a full course refuses new members), and carry lesson sessions with teacher-taken roll call. A course is run by whoever created it plus any teachers a manager assigns to it (`POST /courses/{id}/teachers`) — an assigned teacher manages everything inside the course (exams, sessions, subjects, roster, grading) but cannot delete the course or change who else teaches it, and a demotion below `teacher` drops their assignments. Each course also owns its curriculum as a list of subjects, and every exam question must be tagged with one of its course's subjects (a subject still referenced by questions cannot be deleted); staff clock in/out on a server-stamped work log; students run a pomodoro study timer whose focus sessions land in a server-stamped log (starting discards a dangling unfinished session; teachers can read any student's log and its total focus time); attendance reports tally events and per-course roll call with rates. School-varying policy (exam kinds with their course-average weights, attendance statuses, grade-display bands, the note-file size limit) lives in an editable settings singleton, and courses may link to academic terms. Each account also carries its own UI preferences — theme (`light`/`dark`) and language (`tr`/`en`) — self-managed, admin-editable for anyone, and `null` until chosen (the client then follows the device preference). A `parent` role observes without touching: admins tie any number of students to a parent account (`POST /users/{id}/students`), the parent lists them at `GET /users/me/students` and reads each one's mark, attendance, and pomodoro reports — and nothing else; parents hold no staff power and never act as students (no enrolling, sitting exams, or roll call). A school-wide **question pool** lets students ask for help: a student posts a question (optionally with a photo of the problem — same raster rules and size cap as question images), a teacher+ approves it into the pool (or deletes it — rejection is deletion, there is no rejected state), and every approved question is readable by the whole school (parents excepted), with anyone free to offer solutions under it — text plus an optional photo of the worked steps, both editable by the solution's author at any time, since solutions are unmoderated and never freeze — and every question row carries its `solution_count`; pending questions are visible only to their asker and to teacher+ (whose `?status=pending` list is the approval queue), and approval freezes the question's content so nothing unmoderated can slip into the pool afterwards. While the database connection is reconnecting (a restart, a dropped socket) requests briefly answer `503` with `Retry-After: 1` — transient, retry shortly. Every list endpoint accepts `?limit=&offset=` and returns a `{items, total, limit, offset}` page envelope — paging is opt-in, so omitting `limit` returns the full list and `total` always carries the unpaged count.", | |
| 38 | 38 | ), |
| 39 | 39 | modifiers(&SecurityAddon), |
| 40 | 40 | tags( |
| @@ -44,7 +44,7 @@ use crate::state::AppState; | ||
| 44 | 44 | (name = "notes", description = "Per-user notes CRUD, plus file attachments per note (multipart upload, download, delete — at most 10 per note, each at most the school's settings-configured `max_file_bytes`)"), |
| 45 | 45 | (name = "messages", description = "One-to-one mail-style messages between any two users (parents included — messaging is the one place a parent writes), each optionally tagged with a free-text `label` badge. Each party owns their copy independently: the recipient's moves through `inbox`/`archive`/`trash` with a read flag (visible to the sender as a read receipt), the sender's through `sent`/`trash`. `GET /messages?folder=` lists one folder (`&read=false` narrows to unread — with `limit=1`, `total` is the unread badge); permanent deletion (`DELETE`) works only from the trash and removes the row once both sides have deleted"), |
| 46 | 46 | (name = "events", description = "Events with an audience (school-wide, one role, a course's enrollment, or a registration signup list — the expected-attendee roster; every event stays visible to all) and their attendance: teacher+ marks people in the audience (students never mark, not even themselves), and the roster report joins the expected list with the marks to show who missed. Registration lists are filled seat by seat (teachers place students, staff place only themselves), optionally capped by `capacity`, and close once the event starts"), |
| 47 | - (name = "courses", description = "Courses — kind `course` (regular class), `study` (etüt, a supervised study session), or `club` (kulüp, a student club; same behavior, different label) — optional enroll-time seat `capacity`, enrollment (students only), course exams, and course sessions"), | |
| 47 | + (name = "courses", description = "Courses — kind `course` (regular class), `study` (etüt, a supervised study session), or `club` (kulüp, a student club; same behavior, different label) — optional enroll-time seat `capacity`, enrollment (students only), course exams, and course sessions. A course is run by its creator plus any teachers a manager assigned to it (`POST /courses/{id}/teachers`): assigned teachers manage everything inside the course but cannot delete it or change the assignment list"), | |
| 48 | 48 | (name = "sessions", description = "Lesson sessions and their roll call (session teacher or course manager marks enrolled students; manager+ marks the teacher)"), |
| 49 | 49 | (name = "work", description = "Staff work log: check-in/check-out stamped by the server clock, manager corrections"), |
| 50 | 50 | (name = "pomodoro", description = "Student pomodoro focus log: start/finish stamped by the server clock (starting discards any dangling unfinished session, so a crashed timer never blocks the next one), own history with the unpaged `total_focus_ms` sum, and teacher+ (or linked-parent) reads of any student's log. Breaks and the work/break rhythm stay in the frontend — the backend records only focus stints"), |
| @@ -53,7 +53,7 @@ use crate::state::AppState; | ||
| 53 | 53 | (name = "exams", description = "Exams (per course, weighted by their kind — see `settings`): results, sync/async/open scheduling, attempts (students only — staff never sit) with retakes (`max_attempts`, 0 = unlimited) and a live rejoin door (`allow_rejoin`), questions/answers, and live monitoring (no-shows flagged `absent` once the window closes). Questions may carry images: one illustration per question (any kind — the map the prompt asks about) and one picture per option on `choice` questions, uploaded per slot (multipart, raster types only, ≤ the school's `max_file_bytes`) and frozen with the rest of the question once attempts exist; bytes are served to course managers and to enrolled students once they hold an attempt. A modeless exam is offline-graded — attempts on it are a 409. An exam still being written can be saved as a **draft** (`draft: true` on create, published later by `PATCH`ing `draft: false`): drafts are visible only to the course's managers (students get 404s), cannot be sat or graded, and once attempts or results exist an exam cannot be re-drafted. Not in this spec (WebSocket): the student exam room at `GET /exams/{id}/attempt/ws` — JSON frames; entering clears the attempt's `left_at`, leaving mid-attempt stamps it. See the README's \"Taking an exam\" section for the protocol"), |
| 54 | 54 | (name = "marks", description = "Weighted mark reports per course and overall, labeled by the school's grade bands when configured. Each mark counts its exam kind's settings-configured weight times (weight 1 when the kind was since removed from settings). Own report at `/me`; another user's needs teacher+ (teachers narrowed to their courses) or a parent link to that student"), |
| 55 | 55 | (name = "settings", description = "School policy, one singleton: exam kinds with their course-average weights, attendance statuses, grade-display bands, and the per-file upload size limit (`max_file_bytes` — note files and question images alike). Read: any authenticated user; edit: manager+"), |
| 56 | - (name = "subjects", description = "A course's curriculum topics. Created and listed under `/courses/{id}/subjects`; lookup/edit/delete at `/subjects/{id}`. Every exam question links to one of its course's subjects, so a subject in use cannot be deleted (409) — re-tag or delete the questions first. View follows the course (enrolled users, creator, manager+); edit follows course management rights"), | |
| 56 | + (name = "subjects", description = "A course's curriculum topics. Created and listed under `/courses/{id}/subjects`; lookup/edit/delete at `/subjects/{id}`. Every exam question links to one of its course's subjects, so a subject in use cannot be deleted (409) — re-tag or delete the questions first. View follows the course (enrolled users, creator, assigned teachers, manager+); edit follows course management rights"), | |
| 57 | 57 | (name = "terms", description = "Academic terms (semester/trimester/quarter — whatever the school runs); courses may link to one. Read: any authenticated user; edit: manager+"), |
| 58 | 58 | ), |
| 59 | 59 | )] |
src/web/attendance.rsmodified+2 -2
| @@ -17,7 +17,7 @@ use crate::error::{AppError, ErrorResponse}; | ||
| 17 | 17 | use crate::state::AppState; |
| 18 | 18 | |
| 19 | 19 | use super::courses::can_manage_course; |
| 20 | -use super::{CourseResponse, CurrentUser, ensure_can_observe, person_map}; | |
| 20 | +use super::{CourseResponse, CurrentUser, course_people, ensure_can_observe, person_map}; | |
| 21 | 21 | |
| 22 | 22 | pub fn routes() -> OpenApiRouter<AppState> { |
| 23 | 23 | OpenApiRouter::new() |
| @@ -119,7 +119,7 @@ async fn build_report( | ||
| 119 | 119 | let courses = Course::list_by_ids(&course_ids, db).await?; |
| 120 | 120 | let course_by_key: HashMap<&str, &Course> = |
| 121 | 121 | courses.iter().map(|c| (c.get_id().key(), c)).collect(); |
| 122 | - let people = person_map(courses.iter().map(|c| c.get_creator().clone()), db).await?; | |
| 122 | + let people = person_map(courses.iter().flat_map(course_people), db).await?; | |
| 123 | 123 | |
| 124 | 124 | let mut blocks = Vec::with_capacity(course_ids.len()); |
| 125 | 125 | let mut visible_rows: Vec<&SessionAttendance> = Vec::with_capacity(sessions.len()); |
src/web/courses.rsmodified+154 -39
| @@ -28,9 +28,9 @@ use crate::state::AppState; | ||
| 28 | 28 | use super::sessions::resolve_session_teacher; |
| 29 | 29 | use super::terms::resolve_term; |
| 30 | 30 | use super::{ |
| 31 | - CourseResponse, CurrentUser, ExamResponse, Page, PageParams, PersonRef, RequireTeacher, | |
| 32 | - SessionResponse, SubjectResponse, check_not_past, check_time_range, paginate, person_map, | |
| 33 | - remove_blob, set_or_clear, | |
| 31 | + CourseResponse, CurrentUser, ExamResponse, Page, PageParams, PersonRef, RequireManager, | |
| 32 | + RequireTeacher, SessionResponse, SubjectResponse, check_not_past, check_time_range, | |
| 33 | + course_people, paginate, person_map, remove_blob, set_or_clear, | |
| 34 | 34 | }; |
| 35 | 35 | |
| 36 | 36 | pub fn routes() -> OpenApiRouter<AppState> { |
| @@ -38,6 +38,8 @@ pub fn routes() -> OpenApiRouter<AppState> { | ||
| 38 | 38 | .routes(routes!(create_course, list_courses)) |
| 39 | 39 | .routes(routes!(my_courses)) |
| 40 | 40 | .routes(routes!(get_course, update_course, delete_course)) |
| 41 | + .routes(routes!(assign_teacher)) | |
| 42 | + .routes(routes!(unassign_teacher)) | |
| 41 | 43 | .routes(routes!(enroll, list_roster)) |
| 42 | 44 | .routes(routes!(unenroll)) |
| 43 | 45 | .routes(routes!(create_exam_in_course, list_course_exams)) |
| @@ -89,6 +91,14 @@ struct EnrollUser { | ||
| 89 | 91 | user_id: String, |
| 90 | 92 | } |
| 91 | 93 | |
| 94 | +#[derive(Deserialize, ToSchema)] | |
| 95 | +struct AssignTeacher { | |
| 96 | + /// The staff member to put in charge of the course. Must hold the | |
| 97 | + /// `teacher` role or higher. | |
| 98 | + #[schema(example = "01J8XZ0K3Q8G7X2M4N5P6R7S8T")] | |
| 99 | + user_id: String, | |
| 100 | +} | |
| 101 | + | |
| 92 | 102 | #[derive(Deserialize, ToSchema)] |
| 93 | 103 | struct CreateExamInCourse { |
| 94 | 104 | #[schema(example = "Midterm")] |
| @@ -150,10 +160,23 @@ impl EnrollmentResponse { | ||
| 150 | 160 | } |
| 151 | 161 | } |
| 152 | 162 | |
| 153 | -/// Who may write inside a specific course (edit/delete it, enroll, add exams, | |
| 154 | -/// grade): its creator, or anyone `manager` and above. Callers have already | |
| 155 | -/// cleared the `teacher` bar via `RequireTeacher`. | |
| 163 | +/// Who may write inside a specific course (edit it, enroll, add exams, | |
| 164 | +/// sessions, subjects, grade): its creator, a teacher a manager assigned to | |
| 165 | +/// it, or anyone `manager` and above. Callers have already cleared the | |
| 166 | +/// `teacher` bar via `RequireTeacher`. | |
| 167 | +/// | |
| 168 | +/// Deleting the course and changing its teacher list sit *above* this bar — | |
| 169 | +/// see [`owns_course`]. | |
| 156 | 170 | pub(crate) fn can_manage_course(course: &Course, user: &User) -> bool { |
| 171 | + course.is_creator(user.get_id()) | |
| 172 | + || course.is_assigned(user.get_id()) | |
| 173 | + || user.get_role().at_least(Role::Manager) | |
| 174 | +} | |
| 175 | + | |
| 176 | +/// Who may destroy a course: its creator, or anyone `manager` and above. An | |
| 177 | +/// assigned teacher runs the course but does not own it — they cannot delete | |
| 178 | +/// it out from under the person who made it. | |
| 179 | +fn owns_course(course: &Course, user: &User) -> bool { | |
| 157 | 180 | course.is_creator(user.get_id()) || user.get_role().at_least(Role::Manager) |
| 158 | 181 | } |
| 159 | 182 | |
| @@ -181,7 +204,7 @@ pub(crate) async fn visible_courses(user: &User, db: &Database) -> Result<Vec<Co | ||
| 181 | 204 | if user.get_role().at_least(Role::Manager) { |
| 182 | 205 | return Course::list_all(db).await; |
| 183 | 206 | } |
| 184 | - let mut courses = Course::list_created(user.get_id(), db).await?; | |
| 207 | + let mut courses = Course::list_for_teacher(user.get_id(), db).await?; | |
| 185 | 208 | for course in Course::list_enrolled(user.get_id(), db).await? { |
| 186 | 209 | if !courses |
| 187 | 210 | .iter() |
| @@ -283,7 +306,7 @@ async fn list_courses( | ||
| 283 | 306 | let total = courses.len() as i64; |
| 284 | 307 | let window = paginate(&courses, limit, offset); |
| 285 | 308 | // Join creators onto the page alone — the lookup shrinks with the window. |
| 286 | - let people = person_map(window.iter().map(|c| c.get_creator().clone()), &st.db).await?; | |
| 309 | + let people = person_map(window.iter().flat_map(course_people), &st.db).await?; | |
| 287 | 310 | let items = window |
| 288 | 311 | .iter() |
| 289 | 312 | .map(|course| CourseResponse::new(course, &people)) |
| @@ -315,7 +338,7 @@ async fn my_courses( | ||
| 315 | 338 | let courses = Course::list_enrolled(user.get_id(), &st.db).await?; |
| 316 | 339 | let total = courses.len() as i64; |
| 317 | 340 | let window = paginate(&courses, limit, offset); |
| 318 | - let people = person_map(window.iter().map(|c| c.get_creator().clone()), &st.db).await?; | |
| 341 | + let people = person_map(window.iter().flat_map(course_people), &st.db).await?; | |
| 319 | 342 | let items = window |
| 320 | 343 | .iter() |
| 321 | 344 | .map(|course| CourseResponse::new(course, &people)) |
| @@ -334,7 +357,7 @@ async fn my_courses( | ||
| 334 | 357 | responses( |
| 335 | 358 | (status = 200, description = "The course", body = CourseResponse), |
| 336 | 359 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 337 | - (status = 403, description = "Not enrolled, not the creator, and not a manager/admin", body = ErrorResponse), | |
| 360 | + (status = 403, description = "Not enrolled, not the course creator or an assigned teacher, and not a manager/admin", body = ErrorResponse), | |
| 338 | 361 | (status = 404, description = "Not found", body = ErrorResponse), |
| 339 | 362 | ), |
| 340 | 363 | )] |
| @@ -348,15 +371,16 @@ async fn get_course( | ||
| 348 | 371 | .ok_or(AppError::NotFound)?; |
| 349 | 372 | if !can_view_course(&course, &user, &st.db).await? { |
| 350 | 373 | return Err(AppError::Forbidden( |
| 351 | - "only enrolled users, the course creator, or a manager/admin can view this course", | |
| 374 | + "only enrolled users, the course creator, an assigned teacher, or a manager/admin can view this course", | |
| 352 | 375 | )); |
| 353 | 376 | } |
| 354 | - let people = person_map([course.get_creator().clone()], &st.db).await?; | |
| 377 | + let people = person_map(course_people(&course), &st.db).await?; | |
| 355 | 378 | Ok(Json(CourseResponse::new(&course, &people))) |
| 356 | 379 | } |
| 357 | 380 | |
| 358 | -/// Update a course. Requires teacher+; the creator may edit their own course | |
| 359 | -/// and managers/admins may edit anyone's. Omitted fields keep their value. | |
| 381 | +/// Update a course. Requires teacher+ and course management rights — its | |
| 382 | +/// creator, a teacher assigned to it, or a manager/admin. Omitted fields keep | |
| 383 | +/// their value. | |
| 360 | 384 | #[utoipa::path( |
| 361 | 385 | patch, |
| 362 | 386 | path = "/{id}", |
| @@ -368,7 +392,7 @@ async fn get_course( | ||
| 368 | 392 | (status = 200, description = "Updated course", body = CourseResponse), |
| 369 | 393 | (status = 400, description = "Invalid fields, kind, or capacity", body = ErrorResponse), |
| 370 | 394 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 371 | - (status = 403, description = "Not the creator (and not a manager/admin)", body = ErrorResponse), | |
| 395 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 372 | 396 | (status = 404, description = "Not found", body = ErrorResponse), |
| 373 | 397 | ), |
| 374 | 398 | )] |
| @@ -383,7 +407,7 @@ async fn update_course( | ||
| 383 | 407 | .ok_or(AppError::NotFound)?; |
| 384 | 408 | if !can_manage_course(&course, &user) { |
| 385 | 409 | return Err(AppError::Forbidden( |
| 386 | - "only the course creator or a manager/admin can edit this course", | |
| 410 | + "only the course creator, an assigned teacher, or a manager/admin can edit this course", | |
| 387 | 411 | )); |
| 388 | 412 | } |
| 389 | 413 | |
| @@ -416,12 +440,12 @@ async fn update_course( | ||
| 416 | 440 | let updated = course |
| 417 | 441 | .update(title, description, kind, term, capacity, &st.db) |
| 418 | 442 | .await?; |
| 419 | - let people = person_map([updated.get_creator().clone()], &st.db).await?; | |
| 443 | + let people = person_map(course_people(&updated), &st.db).await?; | |
| 420 | 444 | Ok(Json(CourseResponse::new(&updated, &people))) |
| 421 | 445 | } |
| 422 | 446 | |
| 423 | -/// Delete a course. Requires teacher+; the creator may delete their own course | |
| 424 | -/// and managers/admins may delete anyone's. Cascades the course's exams (with | |
| 447 | +/// Delete a course. Requires teacher+; only its creator or a manager/admin may | |
| 448 | +/// delete it — an assigned teacher runs the course but does not own it. Cascades the course's exams (with | |
| 425 | 449 | /// their results, questions, answers, and question images), its sessions and |
| 426 | 450 | /// roll call, its subjects, and all enrollments. |
| 427 | 451 | #[utoipa::path( |
| @@ -433,7 +457,7 @@ async fn update_course( | ||
| 433 | 457 | responses( |
| 434 | 458 | (status = 204, description = "Deleted"), |
| 435 | 459 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 436 | - (status = 403, description = "Not the creator (and not a manager/admin)", body = ErrorResponse), | |
| 460 | + (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 437 | 461 | (status = 404, description = "Not found", body = ErrorResponse), |
| 438 | 462 | ), |
| 439 | 463 | )] |
| @@ -445,7 +469,7 @@ async fn delete_course( | ||
| 445 | 469 | let course = Course::read(&CourseId::from_key(&id), &st.db) |
| 446 | 470 | .await? |
| 447 | 471 | .ok_or(AppError::NotFound)?; |
| 448 | - if !can_manage_course(&course, &user) { | |
| 472 | + if !owns_course(&course, &user) { | |
| 449 | 473 | return Err(AppError::Forbidden( |
| 450 | 474 | "only the course creator or a manager/admin can delete this course", |
| 451 | 475 | )); |
| @@ -460,6 +484,97 @@ async fn delete_course( | ||
| 460 | 484 | Ok(StatusCode::NO_CONTENT) |
| 461 | 485 | } |
| 462 | 486 | |
| 487 | +// ---- assigned teachers ---------------------------------------------------- | |
| 488 | + | |
| 489 | +/// Assign a teacher to a course (idempotent). Manager+ only — staffing is the | |
| 490 | +/// office's call, so a course's own creator cannot hand management rights to | |
| 491 | +/// their peers. The assignee must already hold the `teacher` role or higher; | |
| 492 | +/// assigning gives them full management of the course (exams, sessions, | |
| 493 | +/// subjects, roster, grading) but not the power to delete it or change this | |
| 494 | +/// list. The course's assigned teachers are returned on every course response. | |
| 495 | +#[utoipa::path( | |
| 496 | + post, | |
| 497 | + path = "/{id}/teachers", | |
| 498 | + tag = "courses", | |
| 499 | + security(("session_cookie" = [])), | |
| 500 | + params(("id" = String, Path, description = "Course id")), | |
| 501 | + request_body = AssignTeacher, | |
| 502 | + responses( | |
| 503 | + (status = 200, description = "Assigned (or already assigned)", body = CourseResponse), | |
| 504 | + (status = 400, description = "Unknown user, or user is not a teacher or higher", body = ErrorResponse), | |
| 505 | + (status = 401, description = "Not authenticated", body = ErrorResponse), | |
| 506 | + (status = 403, description = "Requires manager role or higher", body = ErrorResponse), | |
| 507 | + (status = 404, description = "Course not found", body = ErrorResponse), | |
| 508 | + ), | |
| 509 | +)] | |
| 510 | +async fn assign_teacher( | |
| 511 | + State(st): State<AppState>, | |
| 512 | + RequireManager(_manager): RequireManager, | |
| 513 | + Path(id): Path<String>, | |
| 514 | + Json(req): Json<AssignTeacher>, | |
| 515 | +) -> Result<Json<CourseResponse>, AppError> { | |
| 516 | + let course = Course::read(&CourseId::from_key(&id), &st.db) | |
| 517 | + .await? | |
| 518 | + .ok_or(AppError::NotFound)?; | |
| 519 | + | |
| 520 | + let target = UserId::from_key(&req.user_id); | |
| 521 | + let Some(target_user) = User::read(&target, &st.db).await? else { | |
| 522 | + return Err(AppError::Validation(ValidationError::Invalid { | |
| 523 | + field: "user_id", | |
| 524 | + reason: "target user does not exist", | |
| 525 | + })); | |
| 526 | + }; | |
| 527 | + // Assignment hands out course-management rights, which every gate behind | |
| 528 | + // it re-checks against the `teacher` bar — assigning anyone below it would | |
| 529 | + // write a row that can never be used. | |
| 530 | + if !target_user.get_role().at_least(Role::Teacher) { | |
| 531 | + return Err(AppError::Validation(ValidationError::Invalid { | |
| 532 | + field: "user_id", | |
| 533 | + reason: "assigned teacher must hold the teacher role or higher", | |
| 534 | + })); | |
| 535 | + } | |
| 536 | + | |
| 537 | + let updated = course.assign_teacher(&target, &st.db).await?; | |
| 538 | + let people = person_map(course_people(&updated), &st.db).await?; | |
| 539 | + Ok(Json(CourseResponse::new(&updated, &people))) | |
| 540 | +} | |
| 541 | + | |
| 542 | +/// Unassign a teacher from a course. Manager+ only. The course itself, its | |
| 543 | +/// exams, sessions, and roster are untouched — the teacher just loses their | |
| 544 | +/// management rights over it. A user who was never assigned is a 404. | |
| 545 | +#[utoipa::path( | |
| 546 | + delete, | |
| 547 | + path = "/{id}/teachers/{user}", | |
| 548 | + tag = "courses", | |
| 549 | + security(("session_cookie" = [])), | |
| 550 | + params( | |
| 551 | + ("id" = String, Path, description = "Course id"), | |
| 552 | + ("user" = String, Path, description = "User id"), | |
| 553 | + ), | |
| 554 | + responses( | |
| 555 | + (status = 204, description = "Unassigned"), | |
| 556 | + (status = 401, description = "Not authenticated", body = ErrorResponse), | |
| 557 | + (status = 403, description = "Requires manager role or higher", body = ErrorResponse), | |
| 558 | + (status = 404, description = "Course not found, or that user was not assigned to it", body = ErrorResponse), | |
| 559 | + ), | |
| 560 | +)] | |
| 561 | +async fn unassign_teacher( | |
| 562 | + State(st): State<AppState>, | |
| 563 | + RequireManager(_manager): RequireManager, | |
| 564 | + Path((id, target)): Path<(String, String)>, | |
| 565 | +) -> Result<StatusCode, AppError> { | |
| 566 | + let course = Course::read(&CourseId::from_key(&id), &st.db) | |
| 567 | + .await? | |
| 568 | + .ok_or(AppError::NotFound)?; | |
| 569 | + let removed = course | |
| 570 | + .unassign_teacher(&UserId::from_key(&target), &st.db) | |
| 571 | + .await?; | |
| 572 | + if removed.is_none() { | |
| 573 | + return Err(AppError::NotFound); | |
| 574 | + } | |
| 575 | + Ok(StatusCode::NO_CONTENT) | |
| 576 | +} | |
| 577 | + | |
| 463 | 578 | // ---- enrollments ---------------------------------------------------------- |
| 464 | 579 | |
| 465 | 580 | /// Enroll a user into a course (idempotent upsert). Requires teacher+ and |
| @@ -478,7 +593,7 @@ async fn delete_course( | ||
| 478 | 593 | (status = 200, description = "Enrolled (or already enrolled)", body = EnrollmentResponse), |
| 479 | 594 | (status = 400, description = "Unknown user, or user is not a student", body = ErrorResponse), |
| 480 | 595 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 481 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 596 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 482 | 597 | (status = 404, description = "Course not found", body = ErrorResponse), |
| 483 | 598 | (status = 409, description = "The course is full", body = ErrorResponse), |
| 484 | 599 | ), |
| @@ -494,7 +609,7 @@ async fn enroll( | ||
| 494 | 609 | .ok_or(AppError::NotFound)?; |
| 495 | 610 | if !can_manage_course(&course, &user) { |
| 496 | 611 | return Err(AppError::Forbidden( |
| 497 | - "only the course creator or a manager/admin can enroll users", | |
| 612 | + "only the course creator, an assigned teacher, or a manager/admin can enroll users", | |
| 498 | 613 | )); |
| 499 | 614 | } |
| 500 | 615 | |
| @@ -535,7 +650,7 @@ async fn enroll( | ||
| 535 | 650 | (status = 200, description = "A page of enrollments (the whole roster when unpaged)", body = Page<EnrollmentResponse>), |
| 536 | 651 | (status = 400, description = "Invalid limit or offset", body = ErrorResponse), |
| 537 | 652 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 538 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 653 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 539 | 654 | (status = 404, description = "Course not found", body = ErrorResponse), |
| 540 | 655 | ), |
| 541 | 656 | )] |
| @@ -552,7 +667,7 @@ async fn list_roster( | ||
| 552 | 667 | .ok_or(AppError::NotFound)?; |
| 553 | 668 | if !can_manage_course(&course, &user) { |
| 554 | 669 | return Err(AppError::Forbidden( |
| 555 | - "only the course creator or a manager/admin can list the roster", | |
| 670 | + "only the course creator, an assigned teacher, or a manager/admin can list the roster", | |
| 556 | 671 | )); |
| 557 | 672 | } |
| 558 | 673 | let enrollments = Enrollment::list_for_course(course.get_id(), &st.db).await?; |
| @@ -587,7 +702,7 @@ async fn list_roster( | ||
| 587 | 702 | responses( |
| 588 | 703 | (status = 204, description = "Unenrolled"), |
| 589 | 704 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 590 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 705 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 591 | 706 | (status = 404, description = "Not found", body = ErrorResponse), |
| 592 | 707 | ), |
| 593 | 708 | )] |
| @@ -601,7 +716,7 @@ async fn unenroll( | ||
| 601 | 716 | .ok_or(AppError::NotFound)?; |
| 602 | 717 | if !can_manage_course(&course, &user) { |
| 603 | 718 | return Err(AppError::Forbidden( |
| 604 | - "only the course creator or a manager/admin can unenroll users", | |
| 719 | + "only the course creator, an assigned teacher, or a manager/admin can unenroll users", | |
| 605 | 720 | )); |
| 606 | 721 | } |
| 607 | 722 | let removed = Enrollment::remove(course.get_id(), &UserId::from_key(&target), &st.db).await?; |
| @@ -634,7 +749,7 @@ async fn unenroll( | ||
| 634 | 749 | (status = 201, description = "Exam created", body = ExamResponse), |
| 635 | 750 | (status = 400, description = "Invalid fields, kind, attempt limit, or schedule (malformed window, or times in the past)", body = ErrorResponse), |
| 636 | 751 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 637 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 752 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 638 | 753 | (status = 404, description = "Course not found", body = ErrorResponse), |
| 639 | 754 | ), |
| 640 | 755 | )] |
| @@ -649,7 +764,7 @@ async fn create_exam_in_course( | ||
| 649 | 764 | .ok_or(AppError::NotFound)?; |
| 650 | 765 | if !can_manage_course(&course, &user) { |
| 651 | 766 | return Err(AppError::Forbidden( |
| 652 | - "only the course creator or a manager/admin can add exams to this course", | |
| 767 | + "only the course creator, an assigned teacher, or a manager/admin can add exams to this course", | |
| 653 | 768 | )); |
| 654 | 769 | } |
| 655 | 770 | |
| @@ -701,7 +816,7 @@ async fn create_exam_in_course( | ||
| 701 | 816 | (status = 200, description = "A page of the course's exams (all of them when unpaged)", body = Page<ExamResponse>), |
| 702 | 817 | (status = 400, description = "Invalid limit or offset", body = ErrorResponse), |
| 703 | 818 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 704 | - (status = 403, description = "Not enrolled, not the creator, and not a manager/admin", body = ErrorResponse), | |
| 819 | + (status = 403, description = "Not enrolled, not the course creator or an assigned teacher, and not a manager/admin", body = ErrorResponse), | |
| 705 | 820 | (status = 404, description = "Course not found", body = ErrorResponse), |
| 706 | 821 | ), |
| 707 | 822 | )] |
| @@ -718,7 +833,7 @@ async fn list_course_exams( | ||
| 718 | 833 | .ok_or(AppError::NotFound)?; |
| 719 | 834 | if !can_view_course(&course, &user, &st.db).await? { |
| 720 | 835 | return Err(AppError::Forbidden( |
| 721 | - "only enrolled users, the course creator, or a manager/admin can view this course", | |
| 836 | + "only enrolled users, the course creator, an assigned teacher, or a manager/admin can view this course", | |
| 722 | 837 | )); |
| 723 | 838 | } |
| 724 | 839 | let mut exams = Exam::list_for_course(course.get_id(), &st.db).await?; |
| @@ -759,7 +874,7 @@ struct CreateSubject { | ||
| 759 | 874 | (status = 201, description = "Subject created", body = SubjectResponse), |
| 760 | 875 | (status = 400, description = "Invalid name or description", body = ErrorResponse), |
| 761 | 876 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 762 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 877 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 763 | 878 | (status = 404, description = "Course not found", body = ErrorResponse), |
| 764 | 879 | ), |
| 765 | 880 | )] |
| @@ -774,7 +889,7 @@ async fn create_subject_in_course( | ||
| 774 | 889 | .ok_or(AppError::NotFound)?; |
| 775 | 890 | if !can_manage_course(&course, &user) { |
| 776 | 891 | return Err(AppError::Forbidden( |
| 777 | - "only the course creator or a manager/admin can add subjects to this course", | |
| 892 | + "only the course creator, an assigned teacher, or a manager/admin can add subjects to this course", | |
| 778 | 893 | )); |
| 779 | 894 | } |
| 780 | 895 | |
| @@ -798,7 +913,7 @@ async fn create_subject_in_course( | ||
| 798 | 913 | (status = 200, description = "A page of the course's subjects (all of them when unpaged)", body = Page<SubjectResponse>), |
| 799 | 914 | (status = 400, description = "Invalid limit or offset", body = ErrorResponse), |
| 800 | 915 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 801 | - (status = 403, description = "Not enrolled, not the creator, and not a manager/admin", body = ErrorResponse), | |
| 916 | + (status = 403, description = "Not enrolled, not the course creator or an assigned teacher, and not a manager/admin", body = ErrorResponse), | |
| 802 | 917 | (status = 404, description = "Course not found", body = ErrorResponse), |
| 803 | 918 | ), |
| 804 | 919 | )] |
| @@ -815,7 +930,7 @@ async fn list_course_subjects( | ||
| 815 | 930 | .ok_or(AppError::NotFound)?; |
| 816 | 931 | if !can_view_course(&course, &user, &st.db).await? { |
| 817 | 932 | return Err(AppError::Forbidden( |
| 818 | - "only enrolled users, the course creator, or a manager/admin can view this course", | |
| 933 | + "only enrolled users, the course creator, an assigned teacher, or a manager/admin can view this course", | |
| 819 | 934 | )); |
| 820 | 935 | } |
| 821 | 936 | let subjects = Subject::list_for_course(course.get_id(), &st.db).await?; |
| @@ -858,7 +973,7 @@ struct CreateSessionInCourse { | ||
| 858 | 973 | (status = 201, description = "Session created", body = SessionResponse), |
| 859 | 974 | (status = 400, description = "Invalid fields, time range, times in the past, or teacher", body = ErrorResponse), |
| 860 | 975 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 861 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 976 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 862 | 977 | (status = 404, description = "Course not found", body = ErrorResponse), |
| 863 | 978 | ), |
| 864 | 979 | )] |
| @@ -873,7 +988,7 @@ async fn create_session_in_course( | ||
| 873 | 988 | .ok_or(AppError::NotFound)?; |
| 874 | 989 | if !can_manage_course(&course, &user) { |
| 875 | 990 | return Err(AppError::Forbidden( |
| 876 | - "only the course creator or a manager/admin can add sessions to this course", | |
| 991 | + "only the course creator, an assigned teacher, or a manager/admin can add sessions to this course", | |
| 877 | 992 | )); |
| 878 | 993 | } |
| 879 | 994 | |
| @@ -915,7 +1030,7 @@ async fn create_session_in_course( | ||
| 915 | 1030 | (status = 200, description = "A page of the course's sessions (all of them when unpaged)", body = Page<SessionResponse>), |
| 916 | 1031 | (status = 400, description = "Invalid limit or offset", body = ErrorResponse), |
| 917 | 1032 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 918 | - (status = 403, description = "Not enrolled, not the creator, and not a manager/admin", body = ErrorResponse), | |
| 1033 | + (status = 403, description = "Not enrolled, not the course creator or an assigned teacher, and not a manager/admin", body = ErrorResponse), | |
| 919 | 1034 | (status = 404, description = "Course not found", body = ErrorResponse), |
| 920 | 1035 | ), |
| 921 | 1036 | )] |
| @@ -932,7 +1047,7 @@ async fn list_course_sessions( | ||
| 932 | 1047 | .ok_or(AppError::NotFound)?; |
| 933 | 1048 | if !can_view_course(&course, &user, &st.db).await? { |
| 934 | 1049 | return Err(AppError::Forbidden( |
| 935 | - "only enrolled users, the course creator, or a manager/admin can view this course", | |
| 1050 | + "only enrolled users, the course creator, an assigned teacher, or a manager/admin can view this course", | |
| 936 | 1051 | )); |
| 937 | 1052 | } |
| 938 | 1053 | let sessions = CourseSession::list_for_course(course.get_id(), &st.db).await?; |
src/web/dto.rsmodified+18 -1
| @@ -160,8 +160,13 @@ impl UserResponse { | ||
| 160 | 160 | pub struct CourseResponse { |
| 161 | 161 | #[schema(example = "01J8XZ0K3Q8G7X2M4N5P6R7S8T")] |
| 162 | 162 | pub id: String, |
| 163 | - /// Who created (and owns) the course. | |
| 163 | + /// Who created (and owns) the course. Only they and managers/admins may | |
| 164 | + /// delete it or change who teaches it. | |
| 164 | 165 | pub creator: PersonRef, |
| 166 | + /// The staff a manager assigned to run this course. They manage everything | |
| 167 | + /// inside it — exams, sessions, subjects, the roster, grading — but cannot | |
| 168 | + /// delete the course or change this list. Empty when nobody was assigned. | |
| 169 | + pub teachers: Vec<PersonRef>, | |
| 165 | 170 | #[schema(example = "Algebra")] |
| 166 | 171 | pub title: String, |
| 167 | 172 | pub description: String, |
| @@ -178,11 +183,23 @@ pub struct CourseResponse { | ||
| 178 | 183 | pub capacity: Option<i64>, |
| 179 | 184 | } |
| 180 | 185 | |
| 186 | +/// Every person a [`CourseResponse`] names: the creator plus the teachers | |
| 187 | +/// assigned to run it. Feed this into `person_map` so the response can resolve | |
| 188 | +/// all of them — a name the map is missing renders as an unknown person. | |
| 189 | +pub fn course_people(course: &Course) -> impl Iterator<Item = UserId> + '_ { | |
| 190 | + std::iter::once(course.get_creator().clone()).chain(course.get_teachers().iter().cloned()) | |
| 191 | +} | |
| 192 | + | |
| 181 | 193 | impl CourseResponse { |
| 182 | 194 | pub fn new(course: &Course, people: &HashMap<String, PersonRef>) -> Self { |
| 183 | 195 | Self { |
| 184 | 196 | id: course.get_id().key().to_string(), |
| 185 | 197 | creator: PersonRef::resolve(people, course.get_creator()), |
| 198 | + teachers: course | |
| 199 | + .get_teachers() | |
| 200 | + .iter() | |
| 201 | + .map(|teacher| PersonRef::resolve(people, teacher)) | |
| 202 | + .collect(), | |
| 186 | 203 | title: course.get_title().as_str().to_string(), |
| 187 | 204 | description: course.get_description().as_str().to_string(), |
| 188 | 205 | kind: course.get_kind().as_str().to_string(), |
src/web/exams.rsmodified+32 -32
| @@ -280,7 +280,7 @@ async fn get_exam( | ||
| 280 | 280 | let course = course_of(&exam, &st.db).await?; |
| 281 | 281 | if !can_view_course(&course, &user, &st.db).await? { |
| 282 | 282 | return Err(AppError::Forbidden( |
| 283 | - "only enrolled users, the course creator, or a manager/admin can view this exam", | |
| 283 | + "only enrolled users, the course creator, an assigned teacher, or a manager/admin can view this exam", | |
| 284 | 284 | )); |
| 285 | 285 | } |
| 286 | 286 | // A draft doesn't exist for anyone but its course's managers — 404, not |
| @@ -312,7 +312,7 @@ async fn get_exam( | ||
| 312 | 312 | (status = 200, description = "Updated exam", body = ExamResponse), |
| 313 | 313 | (status = 400, description = "Invalid fields, kind, attempt limit, or schedule (malformed window, or newly set times in the past)", body = ErrorResponse), |
| 314 | 314 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 315 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 315 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 316 | 316 | (status = 404, description = "Not found", body = ErrorResponse), |
| 317 | 317 | (status = 409, description = "Mode change after attempts started, or re-drafting an exam that has attempts or results", body = ErrorResponse), |
| 318 | 318 | ), |
| @@ -334,7 +334,7 @@ async fn update_exam( | ||
| 334 | 334 | let course = course_of(&exam, &st.db).await?; |
| 335 | 335 | if !can_manage_course(&course, &user) { |
| 336 | 336 | return Err(AppError::Forbidden( |
| 337 | - "only the course creator or a manager/admin can edit this exam", | |
| 337 | + "only the course creator, an assigned teacher, or a manager/admin can edit this exam", | |
| 338 | 338 | )); |
| 339 | 339 | } |
| 340 | 340 | |
| @@ -449,7 +449,7 @@ async fn update_exam( | ||
| 449 | 449 | responses( |
| 450 | 450 | (status = 204, description = "Deleted"), |
| 451 | 451 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 452 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 452 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 453 | 453 | (status = 404, description = "Not found", body = ErrorResponse), |
| 454 | 454 | ), |
| 455 | 455 | )] |
| @@ -464,7 +464,7 @@ async fn delete_exam( | ||
| 464 | 464 | let course = course_of(&exam, &st.db).await?; |
| 465 | 465 | if !can_manage_course(&course, &user) { |
| 466 | 466 | return Err(AppError::Forbidden( |
| 467 | - "only the course creator or a manager/admin can delete this exam", | |
| 467 | + "only the course creator, an assigned teacher, or a manager/admin can delete this exam", | |
| 468 | 468 | )); |
| 469 | 469 | } |
| 470 | 470 | // Rows go first (the delete cascades them), blobs after — a crash in |
| @@ -495,7 +495,7 @@ async fn delete_exam( | ||
| 495 | 495 | (status = 200, description = "Result recorded", body = ExamResultResponse), |
| 496 | 496 | (status = 400, description = "Invalid mark, unknown user, user not a student, or not enrolled", body = ErrorResponse), |
| 497 | 497 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 498 | - (status = 403, description = "Not the course creator (and not a manager/admin), or attempted to grade yourself", body = ErrorResponse), | |
| 498 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin), or attempted to grade yourself", body = ErrorResponse), | |
| 499 | 499 | (status = 404, description = "Exam not found", body = ErrorResponse), |
| 500 | 500 | (status = 409, description = "The exam is a draft", body = ErrorResponse), |
| 501 | 501 | ), |
| @@ -519,7 +519,7 @@ async fn grade( | ||
| 519 | 519 | let course = course_of(&exam, &st.db).await?; |
| 520 | 520 | if !can_manage_course(&course, &teacher) { |
| 521 | 521 | return Err(AppError::Forbidden( |
| 522 | - "only the course creator or a manager/admin can grade this exam", | |
| 522 | + "only the course creator, an assigned teacher, or a manager/admin can grade this exam", | |
| 523 | 523 | )); |
| 524 | 524 | } |
| 525 | 525 | if exam.is_draft() { |
| @@ -584,7 +584,7 @@ async fn grade( | ||
| 584 | 584 | (status = 200, description = "A page of results (all of them when unpaged)", body = Page<ExamResultResponse>), |
| 585 | 585 | (status = 400, description = "Invalid limit or offset", body = ErrorResponse), |
| 586 | 586 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 587 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 587 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 588 | 588 | (status = 404, description = "Exam not found", body = ErrorResponse), |
| 589 | 589 | ), |
| 590 | 590 | )] |
| @@ -602,7 +602,7 @@ async fn list_results( | ||
| 602 | 602 | let course = course_of(&exam, &st.db).await?; |
| 603 | 603 | if !can_manage_course(&course, &user) { |
| 604 | 604 | return Err(AppError::Forbidden( |
| 605 | - "only the course creator or a manager/admin can list results", | |
| 605 | + "only the course creator, an assigned teacher, or a manager/admin can list results", | |
| 606 | 606 | )); |
| 607 | 607 | } |
| 608 | 608 | let results = ExamResult::list_for_exam(exam.get_id(), &st.db).await?; |
| @@ -666,7 +666,7 @@ async fn my_result( | ||
| 666 | 666 | responses( |
| 667 | 667 | (status = 204, description = "Removed"), |
| 668 | 668 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 669 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 669 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 670 | 670 | (status = 404, description = "Not found", body = ErrorResponse), |
| 671 | 671 | ), |
| 672 | 672 | )] |
| @@ -681,7 +681,7 @@ async fn remove_result( | ||
| 681 | 681 | let course = course_of(&exam, &st.db).await?; |
| 682 | 682 | if !can_manage_course(&course, &user) { |
| 683 | 683 | return Err(AppError::Forbidden( |
| 684 | - "only the course creator or a manager/admin can remove results", | |
| 684 | + "only the course creator, an assigned teacher, or a manager/admin can remove results", | |
| 685 | 685 | )); |
| 686 | 686 | } |
| 687 | 687 | let removed = ExamResult::remove(exam.get_id(), &UserId::from_key(&target), &st.db).await?; |
| @@ -702,7 +702,7 @@ async fn remove_result( | ||
| 702 | 702 | responses( |
| 703 | 703 | (status = 200, description = "The exam's mark statistics", body = ExamStatisticsResponse), |
| 704 | 704 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 705 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 705 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 706 | 706 | (status = 404, description = "Exam not found", body = ErrorResponse), |
| 707 | 707 | ), |
| 708 | 708 | )] |
| @@ -718,7 +718,7 @@ async fn exam_statistics( | ||
| 718 | 718 | let course = course_of(&exam, &st.db).await?; |
| 719 | 719 | if !can_manage_course(&course, &user) { |
| 720 | 720 | return Err(AppError::Forbidden( |
| 721 | - "only the course creator or a manager/admin can view statistics", | |
| 721 | + "only the course creator, an assigned teacher, or a manager/admin can view statistics", | |
| 722 | 722 | )); |
| 723 | 723 | } |
| 724 | 724 | let results = ExamResult::list_for_exam(exam.get_id(), &st.db).await?; |
| @@ -1226,7 +1226,7 @@ async fn live_snapshot(exam: &Exam, db: &Database) -> Result<ExamLiveResponse, A | ||
| 1226 | 1226 | responses( |
| 1227 | 1227 | (status = 200, description = "Live snapshot", body = ExamLiveResponse), |
| 1228 | 1228 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 1229 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 1229 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 1230 | 1230 | (status = 404, description = "Exam not found", body = ErrorResponse), |
| 1231 | 1231 | ), |
| 1232 | 1232 | )] |
| @@ -1241,7 +1241,7 @@ async fn exam_live( | ||
| 1241 | 1241 | let course = course_of(&exam, &st.db).await?; |
| 1242 | 1242 | if !can_manage_course(&course, &user) { |
| 1243 | 1243 | return Err(AppError::Forbidden( |
| 1244 | - "only the course creator or a manager/admin can monitor this exam", | |
| 1244 | + "only the course creator, an assigned teacher, or a manager/admin can monitor this exam", | |
| 1245 | 1245 | )); |
| 1246 | 1246 | } |
| 1247 | 1247 | Ok(Json(live_snapshot(&exam, &st.db).await?)) |
| @@ -1263,7 +1263,7 @@ async fn exam_live( | ||
| 1263 | 1263 | responses( |
| 1264 | 1264 | (status = 200, description = "SSE feed of `snapshot` events (`ExamLiveResponse` as JSON)", content_type = "text/event-stream"), |
| 1265 | 1265 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 1266 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 1266 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 1267 | 1267 | (status = 404, description = "Exam not found", body = ErrorResponse), |
| 1268 | 1268 | ), |
| 1269 | 1269 | )] |
| @@ -1280,7 +1280,7 @@ async fn exam_live_stream( | ||
| 1280 | 1280 | let course = course_of(&exam, &st.db).await?; |
| 1281 | 1281 | if !can_manage_course(&course, &user) { |
| 1282 | 1282 | return Err(AppError::Forbidden( |
| 1283 | - "only the course creator or a manager/admin can monitor this exam", | |
| 1283 | + "only the course creator, an assigned teacher, or a manager/admin can monitor this exam", | |
| 1284 | 1284 | )); |
| 1285 | 1285 | } |
| 1286 | 1286 | |
| @@ -1507,7 +1507,7 @@ async fn question_of_exam( | ||
| 1507 | 1507 | (status = 201, description = "Question created", body = QuestionResponse), |
| 1508 | 1508 | (status = 400, description = "Invalid text, kind, points, choices, or correct — or an unknown subject, or one from another course", body = ErrorResponse), |
| 1509 | 1509 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 1510 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 1510 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 1511 | 1511 | (status = 404, description = "Exam not found", body = ErrorResponse), |
| 1512 | 1512 | (status = 409, description = "Attempts have started — questions are frozen", body = ErrorResponse), |
| 1513 | 1513 | ), |
| @@ -1524,7 +1524,7 @@ async fn create_question( | ||
| 1524 | 1524 | let course = course_of(&exam, &st.db).await?; |
| 1525 | 1525 | if !can_manage_course(&course, &user) { |
| 1526 | 1526 | return Err(AppError::Forbidden( |
| 1527 | - "only the course creator or a manager/admin can author questions", | |
| 1527 | + "only the course creator, an assigned teacher, or a manager/admin can author questions", | |
| 1528 | 1528 | )); |
| 1529 | 1529 | } |
| 1530 | 1530 | // Writer lease of [`EXAM_LOCK`]: the freeze gate, the subject check, and |
| @@ -1560,7 +1560,7 @@ async fn create_question( | ||
| 1560 | 1560 | (status = 200, description = "A page of the exam's questions (all of them when unpaged)", body = Page<QuestionResponse>), |
| 1561 | 1561 | (status = 400, description = "Invalid limit or offset", body = ErrorResponse), |
| 1562 | 1562 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 1563 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 1563 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 1564 | 1564 | (status = 404, description = "Exam not found", body = ErrorResponse), |
| 1565 | 1565 | ), |
| 1566 | 1566 | )] |
| @@ -1577,7 +1577,7 @@ async fn list_questions( | ||
| 1577 | 1577 | let course = course_of(&exam, &st.db).await?; |
| 1578 | 1578 | if !can_manage_course(&course, &user) { |
| 1579 | 1579 | return Err(AppError::Forbidden( |
| 1580 | - "only the course creator or a manager/admin can read the question list", | |
| 1580 | + "only the course creator, an assigned teacher, or a manager/admin can read the question list", | |
| 1581 | 1581 | )); |
| 1582 | 1582 | } |
| 1583 | 1583 | let questions = ExamQuestion::list_for_exam(exam.get_id(), &st.db).await?; |
| @@ -1616,7 +1616,7 @@ async fn list_questions( | ||
| 1616 | 1616 | (status = 200, description = "Updated question", body = QuestionResponse), |
| 1617 | 1617 | (status = 400, description = "Invalid text, kind, points, choices, or correct — or an unknown subject, or one from another course", body = ErrorResponse), |
| 1618 | 1618 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 1619 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 1619 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 1620 | 1620 | (status = 404, description = "No such exam, or no such question in it", body = ErrorResponse), |
| 1621 | 1621 | (status = 409, description = "Attempts have started — questions are frozen", body = ErrorResponse), |
| 1622 | 1622 | ), |
| @@ -1633,7 +1633,7 @@ async fn update_question( | ||
| 1633 | 1633 | let course = course_of(&exam, &st.db).await?; |
| 1634 | 1634 | if !can_manage_course(&course, &user) { |
| 1635 | 1635 | return Err(AppError::Forbidden( |
| 1636 | - "only the course creator or a manager/admin can edit questions", | |
| 1636 | + "only the course creator, an assigned teacher, or a manager/admin can edit questions", | |
| 1637 | 1637 | )); |
| 1638 | 1638 | } |
| 1639 | 1639 | // Writer lease of [`EXAM_LOCK`]: the freeze gate, the subject check, and |
| @@ -1700,7 +1700,7 @@ async fn update_question( | ||
| 1700 | 1700 | responses( |
| 1701 | 1701 | (status = 204, description = "Deleted"), |
| 1702 | 1702 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 1703 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 1703 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 1704 | 1704 | (status = 404, description = "No such exam, or no such question in it", body = ErrorResponse), |
| 1705 | 1705 | (status = 409, description = "Attempts have started — questions are frozen", body = ErrorResponse), |
| 1706 | 1706 | ), |
| @@ -1716,7 +1716,7 @@ async fn delete_question( | ||
| 1716 | 1716 | let course = course_of(&exam, &st.db).await?; |
| 1717 | 1717 | if !can_manage_course(&course, &user) { |
| 1718 | 1718 | return Err(AppError::Forbidden( |
| 1719 | - "only the course creator or a manager/admin can delete questions", | |
| 1719 | + "only the course creator, an assigned teacher, or a manager/admin can delete questions", | |
| 1720 | 1720 | )); |
| 1721 | 1721 | } |
| 1722 | 1722 | // Writer lease of [`EXAM_LOCK`]: freeze gate + delete are one unit — a |
| @@ -1752,7 +1752,7 @@ async fn image_managed_exam(st: &AppState, user: &User, id: &str) -> Result<Exam | ||
| 1752 | 1752 | let course = course_of(&exam, &st.db).await?; |
| 1753 | 1753 | if !can_manage_course(&course, user) { |
| 1754 | 1754 | return Err(AppError::Forbidden( |
| 1755 | - "only the course creator or a manager/admin can manage question images", | |
| 1755 | + "only the course creator, an assigned teacher, or a manager/admin can manage question images", | |
| 1756 | 1756 | )); |
| 1757 | 1757 | } |
| 1758 | 1758 | Ok(exam) |
| @@ -1842,7 +1842,7 @@ async fn serve_image(st: &AppState, image: &QuestionImage) -> Result<Response, A | ||
| 1842 | 1842 | (status = 201, description = "Image stored", body = ImageMetaResponse), |
| 1843 | 1843 | (status = 400, description = "Missing file field, empty file, or a content type outside the image allowlist", body = ErrorResponse), |
| 1844 | 1844 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 1845 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 1845 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 1846 | 1846 | (status = 404, description = "No such exam, or no such question in it", body = ErrorResponse), |
| 1847 | 1847 | (status = 409, description = "Attempts have started — questions are frozen", body = ErrorResponse), |
| 1848 | 1848 | (status = 413, description = "Image exceeds the school's size limit", body = ErrorResponse), |
| @@ -1918,7 +1918,7 @@ async fn get_question_image( | ||
| 1918 | 1918 | responses( |
| 1919 | 1919 | (status = 204, description = "Deleted"), |
| 1920 | 1920 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 1921 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 1921 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 1922 | 1922 | (status = 404, description = "No such exam, question, or image", body = ErrorResponse), |
| 1923 | 1923 | (status = 409, description = "Attempts have started — questions are frozen", body = ErrorResponse), |
| 1924 | 1924 | ), |
| @@ -1960,7 +1960,7 @@ async fn delete_question_image( | ||
| 1960 | 1960 | (status = 201, description = "Image stored", body = ImageMetaResponse), |
| 1961 | 1961 | (status = 400, description = "Missing file field, empty file, a content type outside the image allowlist, a text question, or an index past the choices", body = ErrorResponse), |
| 1962 | 1962 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 1963 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 1963 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 1964 | 1964 | (status = 404, description = "No such exam, or no such question in it", body = ErrorResponse), |
| 1965 | 1965 | (status = 409, description = "Attempts have started — questions are frozen", body = ErrorResponse), |
| 1966 | 1966 | (status = 413, description = "Image exceeds the school's size limit", body = ErrorResponse), |
| @@ -2052,7 +2052,7 @@ async fn get_choice_image( | ||
| 2052 | 2052 | responses( |
| 2053 | 2053 | (status = 204, description = "Deleted"), |
| 2054 | 2054 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 2055 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 2055 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 2056 | 2056 | (status = 404, description = "No such exam, question, or image", body = ErrorResponse), |
| 2057 | 2057 | (status = 409, description = "Attempts have started — questions are frozen", body = ErrorResponse), |
| 2058 | 2058 | ), |
| @@ -2398,7 +2398,7 @@ async fn save_answer( | ||
| 2398 | 2398 | responses( |
| 2399 | 2399 | (status = 200, description = "The student's answers, judged", body = AttemptAnswersResponse), |
| 2400 | 2400 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 2401 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 2401 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 2402 | 2402 | (status = 404, description = "No such exam, or the student has no attempt", body = ErrorResponse), |
| 2403 | 2403 | ), |
| 2404 | 2404 | )] |
| @@ -2413,7 +2413,7 @@ async fn attempt_answers( | ||
| 2413 | 2413 | let course = course_of(&exam, &st.db).await?; |
| 2414 | 2414 | if !can_manage_course(&course, &user) { |
| 2415 | 2415 | return Err(AppError::Forbidden( |
| 2416 | - "only the course creator or a manager/admin can read answer sheets", | |
| 2416 | + "only the course creator, an assigned teacher, or a manager/admin can read answer sheets", | |
| 2417 | 2417 | )); |
| 2418 | 2418 | } |
| 2419 | 2419 | let target = UserId::from_key(&target); |
src/web/marks.rsmodified+2 -2
| @@ -18,7 +18,7 @@ use crate::error::{AppError, ErrorResponse}; | ||
| 18 | 18 | use crate::state::AppState; |
| 19 | 19 | |
| 20 | 20 | use super::courses::can_manage_course; |
| 21 | -use super::{CourseResponse, CurrentUser, ensure_can_observe, person_map}; | |
| 21 | +use super::{CourseResponse, CurrentUser, course_people, ensure_can_observe, person_map}; | |
| 22 | 22 | |
| 23 | 23 | pub fn routes() -> OpenApiRouter<AppState> { |
| 24 | 24 | OpenApiRouter::new() |
| @@ -102,7 +102,7 @@ async fn build_report( | ||
| 102 | 102 | |
| 103 | 103 | // One settings read weighs and labels the whole report. |
| 104 | 104 | let school = Settings::load(db).await?; |
| 105 | - let people = person_map(courses.iter().map(|c| c.get_creator().clone()), db).await?; | |
| 105 | + let people = person_map(courses.iter().flat_map(course_people), db).await?; | |
| 106 | 106 | |
| 107 | 107 | let mut blocks = Vec::with_capacity(courses.len()); |
| 108 | 108 | for course in &courses { |
src/web/mod.rsmodified+8 -6
| @@ -27,7 +27,7 @@ mod page; | ||
| 27 | 27 | |
| 28 | 28 | pub use dto::{ |
| 29 | 29 | CourseResponse, ExamResponse, PersonRef, SessionResponse, SubjectResponse, UserResponse, |
| 30 | - person_map, | |
| 30 | + course_people, person_map, | |
| 31 | 31 | }; |
| 32 | 32 | pub use extractor::{CurrentUser, RequireAdmin, RequireManager, RequireStudent, RequireTeacher}; |
| 33 | 33 | pub use page::{Page, PageParams, paginate}; |
| @@ -168,11 +168,13 @@ pub(crate) async fn serve_inline_blob( | ||
| 168 | 168 | file: &str, |
| 169 | 169 | content_type: &FileContentType, |
| 170 | 170 | ) -> Result<Response, AppError> { |
| 171 | - let bytes = tokio::fs::read(blob_path(files_path, file)).await.map_err(|err| { | |
| 172 | - // The row exists but its blob doesn't — server-side damage (a lost | |
| 173 | - // volume path), not a client 404. | |
| 174 | - AppError::Internal(format!("missing blob for image {file}: {err}")) | |
| 175 | - })?; | |
| 171 | + let bytes = tokio::fs::read(blob_path(files_path, file)) | |
| 172 | + .await | |
| 173 | + .map_err(|err| { | |
| 174 | + // The row exists but its blob doesn't — server-side damage (a lost | |
| 175 | + // volume path), not a client 404. | |
| 176 | + AppError::Internal(format!("missing blob for image {file}: {err}")) | |
| 177 | + })?; | |
| 176 | 178 | let content_type = HeaderValue::from_str(content_type.as_str()) |
| 177 | 179 | .unwrap_or_else(|_| HeaderValue::from_static("application/octet-stream")); |
| 178 | 180 | Ok(( |
src/web/sessions.rsmodified+6 -6
| @@ -134,7 +134,7 @@ fn can_roll_call(session: &CourseSession, course: &Course, user: &User) -> bool | ||
| 134 | 134 | // ---- sessions ------------------------------------------------------------- |
| 135 | 135 | |
| 136 | 136 | /// Fetch a single session by id. Visible to its course's enrolled users, the |
| 137 | -/// session's teacher, the course creator, and managers/admins. | |
| 137 | +/// session's teacher, the course's own teachers, and managers/admins. | |
| 138 | 138 | #[utoipa::path( |
| 139 | 139 | get, |
| 140 | 140 | path = "/{id}", |
| @@ -156,7 +156,7 @@ async fn get_session( | ||
| 156 | 156 | let (session, course) = session_with_course(&id, &st.db).await?; |
| 157 | 157 | if !session.is_teacher(user.get_id()) && !can_view_course(&course, &user, &st.db).await? { |
| 158 | 158 | return Err(AppError::Forbidden( |
| 159 | - "only enrolled users, the session teacher, the course creator, or a manager/admin can view this session", | |
| 159 | + "only enrolled users, the session teacher, the course's teachers, or a manager/admin can view this session", | |
| 160 | 160 | )); |
| 161 | 161 | } |
| 162 | 162 | let people = person_map([session.get_teacher().clone()], &st.db).await?; |
| @@ -176,7 +176,7 @@ async fn get_session( | ||
| 176 | 176 | (status = 200, description = "Updated session", body = SessionResponse), |
| 177 | 177 | (status = 400, description = "Invalid fields, time range, newly set times in the past, or teacher", body = ErrorResponse), |
| 178 | 178 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 179 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 179 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 180 | 180 | (status = 404, description = "Not found", body = ErrorResponse), |
| 181 | 181 | ), |
| 182 | 182 | )] |
| @@ -189,7 +189,7 @@ async fn update_session( | ||
| 189 | 189 | let (session, course) = session_with_course(&id, &st.db).await?; |
| 190 | 190 | if !can_manage_course(&course, &user) { |
| 191 | 191 | return Err(AppError::Forbidden( |
| 192 | - "only the course creator or a manager/admin can edit this session", | |
| 192 | + "only the course creator, an assigned teacher, or a manager/admin can edit this session", | |
| 193 | 193 | )); |
| 194 | 194 | } |
| 195 | 195 | |
| @@ -244,7 +244,7 @@ async fn update_session( | ||
| 244 | 244 | responses( |
| 245 | 245 | (status = 204, description = "Deleted"), |
| 246 | 246 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 247 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 247 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 248 | 248 | (status = 404, description = "Not found", body = ErrorResponse), |
| 249 | 249 | ), |
| 250 | 250 | )] |
| @@ -256,7 +256,7 @@ async fn delete_session( | ||
| 256 | 256 | let (session, course) = session_with_course(&id, &st.db).await?; |
| 257 | 257 | if !can_manage_course(&course, &user) { |
| 258 | 258 | return Err(AppError::Forbidden( |
| 259 | - "only the course creator or a manager/admin can delete this session", | |
| 259 | + "only the course creator, an assigned teacher, or a manager/admin can delete this session", | |
| 260 | 260 | )); |
| 261 | 261 | } |
| 262 | 262 | session.delete(&st.db).await?; |
src/web/subjects.rsmodified+8 -7
| @@ -65,7 +65,8 @@ async fn subject_with_course(id: &str, db: &Database) -> Result<(Subject, Course | ||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /// Fetch a single subject by id. Visible to whoever can view its course: the |
| 68 | -/// course's enrolled users, its creator, and managers/admins. | |
| 68 | +/// course's enrolled users, its creator, its assigned teachers, and | |
| 69 | +/// managers/admins. | |
| 69 | 70 | #[utoipa::path( |
| 70 | 71 | get, |
| 71 | 72 | path = "/{id}", |
| @@ -75,7 +76,7 @@ async fn subject_with_course(id: &str, db: &Database) -> Result<(Subject, Course | ||
| 75 | 76 | responses( |
| 76 | 77 | (status = 200, description = "The subject", body = SubjectResponse), |
| 77 | 78 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 78 | - (status = 403, description = "Not enrolled, not the course creator, and not a manager/admin", body = ErrorResponse), | |
| 79 | + (status = 403, description = "Not enrolled, not the course creator or an assigned teacher, and not a manager/admin", body = ErrorResponse), | |
| 79 | 80 | (status = 404, description = "Not found", body = ErrorResponse), |
| 80 | 81 | ), |
| 81 | 82 | )] |
| @@ -87,7 +88,7 @@ async fn get_subject( | ||
| 87 | 88 | let (subject, course) = subject_with_course(&id, &st.db).await?; |
| 88 | 89 | if !can_view_course(&course, &user, &st.db).await? { |
| 89 | 90 | return Err(AppError::Forbidden( |
| 90 | - "only enrolled users, the course creator, or a manager/admin can view this subject", | |
| 91 | + "only enrolled users, the course creator, an assigned teacher, or a manager/admin can view this subject", | |
| 91 | 92 | )); |
| 92 | 93 | } |
| 93 | 94 | Ok(Json(SubjectResponse::new(&subject))) |
| @@ -107,7 +108,7 @@ async fn get_subject( | ||
| 107 | 108 | (status = 200, description = "Updated subject", body = SubjectResponse), |
| 108 | 109 | (status = 400, description = "Invalid name or description", body = ErrorResponse), |
| 109 | 110 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 110 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 111 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 111 | 112 | (status = 404, description = "Not found", body = ErrorResponse), |
| 112 | 113 | ), |
| 113 | 114 | )] |
| @@ -120,7 +121,7 @@ async fn update_subject( | ||
| 120 | 121 | let (subject, course) = subject_with_course(&id, &st.db).await?; |
| 121 | 122 | if !can_manage_course(&course, &user) { |
| 122 | 123 | return Err(AppError::Forbidden( |
| 123 | - "only the course creator or a manager/admin can edit this subject", | |
| 124 | + "only the course creator, an assigned teacher, or a manager/admin can edit this subject", | |
| 124 | 125 | )); |
| 125 | 126 | } |
| 126 | 127 | |
| @@ -149,7 +150,7 @@ async fn update_subject( | ||
| 149 | 150 | responses( |
| 150 | 151 | (status = 204, description = "Deleted"), |
| 151 | 152 | (status = 401, description = "Not authenticated", body = ErrorResponse), |
| 152 | - (status = 403, description = "Not the course creator (and not a manager/admin)", body = ErrorResponse), | |
| 153 | + (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse), | |
| 153 | 154 | (status = 404, description = "Not found", body = ErrorResponse), |
| 154 | 155 | (status = 409, description = "Exam questions still reference this subject", body = ErrorResponse), |
| 155 | 156 | ), |
| @@ -162,7 +163,7 @@ async fn delete_subject( | ||
| 162 | 163 | let (subject, course) = subject_with_course(&id, &st.db).await?; |
| 163 | 164 | if !can_manage_course(&course, &user) { |
| 164 | 165 | return Err(AppError::Forbidden( |
| 165 | - "only the course creator or a manager/admin can delete this subject", | |
| 166 | + "only the course creator, an assigned teacher, or a manager/admin can delete this subject", | |
| 166 | 167 | )); |
| 167 | 168 | } |
| 168 | 169 | // Writer lease of [`EXAM_LOCK`]: the no-questions check and the delete |
src/web/users.rsmodified+9 -1
| @@ -7,6 +7,7 @@ use utoipa_axum::router::OpenApiRouter; | ||
| 7 | 7 | use utoipa_axum::routes; |
| 8 | 8 | |
| 9 | 9 | use crate::database::Database; |
| 10 | +use crate::domain::course::Course; | |
| 10 | 11 | use crate::domain::enrollment::Enrollment; |
| 11 | 12 | use crate::domain::parent_link::ParentLink; |
| 12 | 13 | use crate::domain::preferences::{Language, Theme}; |
| @@ -366,7 +367,8 @@ async fn update_user_preferences( | ||
| 366 | 367 | /// guard keeps a sole admin from accidentally locking everyone out of role |
| 367 | 368 | /// management (recover such a lockout with the SurrealQL in the README). |
| 368 | 369 | /// Setting any non-`student` role also drops the user's course enrollments — |
| 369 | -/// only students enroll, so a promoted user leaves every roster. | |
| 370 | +/// only students enroll, so a promoted user leaves every roster. Demoting below | |
| 371 | +/// `teacher` drops their course teaching assignments for the mirror reason. | |
| 370 | 372 | #[utoipa::path( |
| 371 | 373 | patch, |
| 372 | 374 | path = "/{id}/role", |
| @@ -410,6 +412,12 @@ async fn set_role( | ||
| 410 | 412 | if role != Role::Parent { |
| 411 | 413 | ParentLink::delete_where_parent(&target, &st.db).await?; |
| 412 | 414 | } |
| 415 | + // Course staffing gets the same sweep: only teacher+ may be assigned to | |
| 416 | + // run a course, so a demotion drops every assignment instead of leaving | |
| 417 | + // rows that grant nothing and still list a demoted user as its teacher. | |
| 418 | + if !role.at_least(Role::Teacher) { | |
| 419 | + Course::unassign_everywhere(&target, &st.db).await?; | |
| 420 | + } | |
| 413 | 421 | Ok(Json(UserResponse::new(&updated))) |
| 414 | 422 | } |
| 415 | 423 |
tests/integration.rsmodified+323 -14
| @@ -2174,6 +2174,247 @@ async fn courses_are_owner_scoped_and_creator_guarded() { | ||
| 2174 | 2174 | ); |
| 2175 | 2175 | } |
| 2176 | 2176 | |
| 2177 | +/// A manager can put a second teacher in charge of someone else's course. The | |
| 2178 | +/// assignee then manages everything inside it, but the course stays its | |
| 2179 | +/// creator's to delete — and a demotion takes the assignment away. | |
| 2180 | +#[tokio::test] | |
| 2181 | +async fn assigned_teacher_manages_course_without_owning_it() { | |
| 2182 | + let (app, db) = app_and_db().await; | |
| 2183 | + let ali = login_as(&app, &db, "ali", "teacher").await; | |
| 2184 | + let veli = login_as(&app, &db, "veli", "teacher").await; | |
| 2185 | + let boss = login_as(&app, &db, "boss", "manager").await; | |
| 2186 | + let rektor = login_as(&app, &db, "rektor", "admin").await; | |
| 2187 | + let veli_id = id_of(&send(&app, "GET", "/auth/me", Some(&veli), None).await.body); | |
| 2188 | + | |
| 2189 | + let course_id = id_of( | |
| 2190 | + &send( | |
| 2191 | + &app, | |
| 2192 | + "POST", | |
| 2193 | + "/courses", | |
| 2194 | + Some(&ali), | |
| 2195 | + Some(json!({ "title": "algebra" })), | |
| 2196 | + ) | |
| 2197 | + .await | |
| 2198 | + .body, | |
| 2199 | + ); | |
| 2200 | + let teachers = format!("/courses/{course_id}/teachers"); | |
| 2201 | + | |
| 2202 | + // Before assignment veli is just another teacher: no read, no write. | |
| 2203 | + assert_eq!( | |
| 2204 | + send( | |
| 2205 | + &app, | |
| 2206 | + "GET", | |
| 2207 | + &format!("/courses/{course_id}"), | |
| 2208 | + Some(&veli), | |
| 2209 | + None | |
| 2210 | + ) | |
| 2211 | + .await | |
| 2212 | + .status, | |
| 2213 | + StatusCode::FORBIDDEN | |
| 2214 | + ); | |
| 2215 | + | |
| 2216 | + // Staffing is the office's call — the course's own creator cannot do it. | |
| 2217 | + assert_eq!( | |
| 2218 | + send( | |
| 2219 | + &app, | |
| 2220 | + "POST", | |
| 2221 | + &teachers, | |
| 2222 | + Some(&ali), | |
| 2223 | + Some(json!({ "user_id": veli_id })) | |
| 2224 | + ) | |
| 2225 | + .await | |
| 2226 | + .status, | |
| 2227 | + StatusCode::FORBIDDEN | |
| 2228 | + ); | |
| 2229 | + | |
| 2230 | + // Only teacher+ can be assigned. | |
| 2231 | + let student = login_as(&app, &db, "zeynep", "student").await; | |
| 2232 | + let student_id = id_of( | |
| 2233 | + &send(&app, "GET", "/auth/me", Some(&student), None) | |
| 2234 | + .await | |
| 2235 | + .body, | |
| 2236 | + ); | |
| 2237 | + assert_eq!( | |
| 2238 | + send( | |
| 2239 | + &app, | |
| 2240 | + "POST", | |
| 2241 | + &teachers, | |
| 2242 | + Some(&boss), | |
| 2243 | + Some(json!({ "user_id": student_id })) | |
| 2244 | + ) | |
| 2245 | + .await | |
| 2246 | + .status, | |
| 2247 | + StatusCode::BAD_REQUEST | |
| 2248 | + ); | |
| 2249 | + | |
| 2250 | + // The manager assigns veli; the course echoes its staff back. | |
| 2251 | + let res = send( | |
| 2252 | + &app, | |
| 2253 | + "POST", | |
| 2254 | + &teachers, | |
| 2255 | + Some(&boss), | |
| 2256 | + Some(json!({ "user_id": veli_id })), | |
| 2257 | + ) | |
| 2258 | + .await; | |
| 2259 | + assert_eq!(res.status, StatusCode::OK); | |
| 2260 | + assert_eq!(res.body["creator"]["username"], "ali"); | |
| 2261 | + assert_eq!(res.body["teachers"][0]["username"], "veli"); | |
| 2262 | + | |
| 2263 | + // Assigning twice is idempotent — no duplicate row in the list. | |
| 2264 | + let again = send( | |
| 2265 | + &app, | |
| 2266 | + "POST", | |
| 2267 | + &teachers, | |
| 2268 | + Some(&boss), | |
| 2269 | + Some(json!({ "user_id": veli_id })), | |
| 2270 | + ) | |
| 2271 | + .await; | |
| 2272 | + assert_eq!(again.status, StatusCode::OK); | |
| 2273 | + assert_eq!(again.body["teachers"].as_array().unwrap().len(), 1); | |
| 2274 | + | |
| 2275 | + // Veli now runs the course: it shows in their catalog, and they can edit | |
| 2276 | + // it and enroll students. | |
| 2277 | + let catalog = send(&app, "GET", "/courses", Some(&veli), None).await.body; | |
| 2278 | + assert_eq!(common::items(&catalog).len(), 1); | |
| 2279 | + assert_eq!( | |
| 2280 | + send( | |
| 2281 | + &app, | |
| 2282 | + "PATCH", | |
| 2283 | + &format!("/courses/{course_id}"), | |
| 2284 | + Some(&veli), | |
| 2285 | + Some(json!({"description":"letters"})) | |
| 2286 | + ) | |
| 2287 | + .await | |
| 2288 | + .status, | |
| 2289 | + StatusCode::OK | |
| 2290 | + ); | |
| 2291 | + assert_eq!( | |
| 2292 | + send( | |
| 2293 | + &app, | |
| 2294 | + "POST", | |
| 2295 | + &format!("/courses/{course_id}/enrollments"), | |
| 2296 | + Some(&veli), | |
| 2297 | + Some(json!({ "user_id": student_id })) | |
| 2298 | + ) | |
| 2299 | + .await | |
| 2300 | + .status, | |
| 2301 | + StatusCode::OK | |
| 2302 | + ); | |
| 2303 | + | |
| 2304 | + // But the course is not theirs to delete, nor to re-staff. | |
| 2305 | + assert_eq!( | |
| 2306 | + send( | |
| 2307 | + &app, | |
| 2308 | + "DELETE", | |
| 2309 | + &format!("/courses/{course_id}"), | |
| 2310 | + Some(&veli), | |
| 2311 | + None | |
| 2312 | + ) | |
| 2313 | + .await | |
| 2314 | + .status, | |
| 2315 | + StatusCode::FORBIDDEN | |
| 2316 | + ); | |
| 2317 | + assert_eq!( | |
| 2318 | + send( | |
| 2319 | + &app, | |
| 2320 | + "DELETE", | |
| 2321 | + &format!("{teachers}/{veli_id}"), | |
| 2322 | + Some(&veli), | |
| 2323 | + None | |
| 2324 | + ) | |
| 2325 | + .await | |
| 2326 | + .status, | |
| 2327 | + StatusCode::FORBIDDEN | |
| 2328 | + ); | |
| 2329 | + | |
| 2330 | + // Demoting veli below teacher sweeps the assignment: the course drops off | |
| 2331 | + // their catalog and the rights go with it. | |
| 2332 | + assert_eq!( | |
| 2333 | + send( | |
| 2334 | + &app, | |
| 2335 | + "PATCH", | |
| 2336 | + &format!("/users/{veli_id}/role"), | |
| 2337 | + Some(&rektor), | |
| 2338 | + Some(json!({"role":"student"})) | |
| 2339 | + ) | |
| 2340 | + .await | |
| 2341 | + .status, | |
| 2342 | + StatusCode::OK | |
| 2343 | + ); | |
| 2344 | + let after = send( | |
| 2345 | + &app, | |
| 2346 | + "GET", | |
| 2347 | + &format!("/courses/{course_id}"), | |
| 2348 | + Some(&ali), | |
| 2349 | + None, | |
| 2350 | + ) | |
| 2351 | + .await; | |
| 2352 | + assert_eq!( | |
| 2353 | + after.body["teachers"].as_array().unwrap().len(), | |
| 2354 | + 0, | |
| 2355 | + "a demoted teacher is swept off the courses they were assigned to" | |
| 2356 | + ); | |
| 2357 | + | |
| 2358 | + // Re-assign, then unassign by hand: the second removal is a 404. | |
| 2359 | + send( | |
| 2360 | + &app, | |
| 2361 | + "PATCH", | |
| 2362 | + &format!("/users/{veli_id}/role"), | |
| 2363 | + Some(&rektor), | |
| 2364 | + Some(json!({"role":"teacher"})), | |
| 2365 | + ) | |
| 2366 | + .await; | |
| 2367 | + assert_eq!( | |
| 2368 | + send( | |
| 2369 | + &app, | |
| 2370 | + "POST", | |
| 2371 | + &teachers, | |
| 2372 | + Some(&boss), | |
| 2373 | + Some(json!({ "user_id": veli_id })) | |
| 2374 | + ) | |
| 2375 | + .await | |
| 2376 | + .status, | |
| 2377 | + StatusCode::OK | |
| 2378 | + ); | |
| 2379 | + assert_eq!( | |
| 2380 | + send( | |
| 2381 | + &app, | |
| 2382 | + "DELETE", | |
| 2383 | + &format!("{teachers}/{veli_id}"), | |
| 2384 | + Some(&boss), | |
| 2385 | + None | |
| 2386 | + ) | |
| 2387 | + .await | |
| 2388 | + .status, | |
| 2389 | + StatusCode::NO_CONTENT | |
| 2390 | + ); | |
| 2391 | + assert_eq!( | |
| 2392 | + send( | |
| 2393 | + &app, | |
| 2394 | + "DELETE", | |
| 2395 | + &format!("{teachers}/{veli_id}"), | |
| 2396 | + Some(&boss), | |
| 2397 | + None | |
| 2398 | + ) | |
| 2399 | + .await | |
| 2400 | + .status, | |
| 2401 | + StatusCode::NOT_FOUND | |
| 2402 | + ); | |
| 2403 | + assert_eq!( | |
| 2404 | + send( | |
| 2405 | + &app, | |
| 2406 | + "GET", | |
| 2407 | + &format!("/courses/{course_id}"), | |
| 2408 | + Some(&veli), | |
| 2409 | + None | |
| 2410 | + ) | |
| 2411 | + .await | |
| 2412 | + .status, | |
| 2413 | + StatusCode::FORBIDDEN, | |
| 2414 | + "unassigning takes the course back out of their reach" | |
| 2415 | + ); | |
| 2416 | +} | |
| 2417 | + | |
| 2177 | 2418 | #[tokio::test] |
| 2178 | 2419 | async fn course_input_validation() { |
| 2179 | 2420 | let (app, db) = app_and_db().await; |
| @@ -5032,7 +5273,11 @@ async fn db_down_refuses_before_touching_the_database() { | ||
| 5032 | 5273 | .await |
| 5033 | 5274 | .unwrap(); |
| 5034 | 5275 | assert_eq!(ok.status(), StatusCode::CREATED); |
| 5035 | - assert_eq!(count_rows(&db, "user").await, before + 1, "the write landed"); | |
| 5276 | + assert_eq!( | |
| 5277 | + count_rows(&db, "user").await, | |
| 5278 | + before + 1, | |
| 5279 | + "the write landed" | |
| 5280 | + ); | |
| 5036 | 5281 | |
| 5037 | 5282 | // Socket reported down: refused with a retryable 503, and — the point of |
| 5038 | 5283 | // refusing at the edge rather than timing out — nothing was written. |
| @@ -11543,7 +11788,14 @@ async fn question_pool_lifecycle() { | ||
| 11543 | 11788 | |
| 11544 | 11789 | // Only students ask: the teacher is refused. |
| 11545 | 11790 | let ask = json!({ "title": "Integral", "body": "∫x·eˣ dx?" }); |
| 11546 | - let res = send(&app, "POST", "/questions", Some(&teacher), Some(ask.clone())).await; | |
| 11791 | + let res = send( | |
| 11792 | + &app, | |
| 11793 | + "POST", | |
| 11794 | + "/questions", | |
| 11795 | + Some(&teacher), | |
| 11796 | + Some(ask.clone()), | |
| 11797 | + ) | |
| 11798 | + .await; | |
| 11547 | 11799 | assert_eq!(res.status, StatusCode::FORBIDDEN, "{}", res.body); |
| 11548 | 11800 | |
| 11549 | 11801 | let res = send(&app, "POST", "/questions", Some(&asker), Some(ask)).await; |
| @@ -11554,8 +11806,19 @@ async fn question_pool_lifecycle() { | ||
| 11554 | 11806 | // Pending: the asker and the teacher see it; another student must not |
| 11555 | 11807 | // even learn it exists — and it takes no solutions yet. |
| 11556 | 11808 | for (cookie, visible) in [(&asker, true), (&teacher, true), (&stranger, false)] { |
| 11557 | - let res = send(&app, "GET", &format!("/questions/{qid}"), Some(cookie), None).await; | |
| 11558 | - let expected = if visible { StatusCode::OK } else { StatusCode::NOT_FOUND }; | |
| 11809 | + let res = send( | |
| 11810 | + &app, | |
| 11811 | + "GET", | |
| 11812 | + &format!("/questions/{qid}"), | |
| 11813 | + Some(cookie), | |
| 11814 | + None, | |
| 11815 | + ) | |
| 11816 | + .await; | |
| 11817 | + let expected = if visible { | |
| 11818 | + StatusCode::OK | |
| 11819 | + } else { | |
| 11820 | + StatusCode::NOT_FOUND | |
| 11821 | + }; | |
| 11559 | 11822 | assert_eq!(res.status, expected, "{}", res.body); |
| 11560 | 11823 | } |
| 11561 | 11824 | let offer = json!({ "body": "Kısmi integrasyon." }); |
| @@ -11571,7 +11834,14 @@ async fn question_pool_lifecycle() { | ||
| 11571 | 11834 | |
| 11572 | 11835 | // The teacher's ?status=pending list is the approval queue; approval is |
| 11573 | 11836 | // teacher-gated and one-way. |
| 11574 | - let res = send(&app, "GET", "/questions?status=pending", Some(&teacher), None).await; | |
| 11837 | + let res = send( | |
| 11838 | + &app, | |
| 11839 | + "GET", | |
| 11840 | + "/questions?status=pending", | |
| 11841 | + Some(&teacher), | |
| 11842 | + None, | |
| 11843 | + ) | |
| 11844 | + .await; | |
| 11575 | 11845 | assert_eq!(common::total(&res.body), 1); |
| 11576 | 11846 | let res = send( |
| 11577 | 11847 | &app, |
| @@ -11638,9 +11908,23 @@ async fn question_pool_lifecycle() { | ||
| 11638 | 11908 | assert_eq!(res.status, StatusCode::NO_CONTENT, "{}", res.body); |
| 11639 | 11909 | |
| 11640 | 11910 | // Question delete (asker withdraws) cascades what's left. |
| 11641 | - let res = send(&app, "DELETE", &format!("/questions/{qid}"), Some(&asker), None).await; | |
| 11911 | + let res = send( | |
| 11912 | + &app, | |
| 11913 | + "DELETE", | |
| 11914 | + &format!("/questions/{qid}"), | |
| 11915 | + Some(&asker), | |
| 11916 | + None, | |
| 11917 | + ) | |
| 11918 | + .await; | |
| 11642 | 11919 | assert_eq!(res.status, StatusCode::NO_CONTENT, "{}", res.body); |
| 11643 | - let res = send(&app, "GET", &format!("/questions/{qid}"), Some(&teacher), None).await; | |
| 11920 | + let res = send( | |
| 11921 | + &app, | |
| 11922 | + "GET", | |
| 11923 | + &format!("/questions/{qid}"), | |
| 11924 | + Some(&teacher), | |
| 11925 | + None, | |
| 11926 | + ) | |
| 11927 | + .await; | |
| 11644 | 11928 | assert_eq!(res.status, StatusCode::NOT_FOUND, "{}", res.body); |
| 11645 | 11929 | } |
| 11646 | 11930 | |
| @@ -11714,7 +11998,8 @@ async fn question_pool_image_upload_and_freeze() { | ||
| 11714 | 11998 | assert_eq!(status, StatusCode::OK); |
| 11715 | 11999 | assert_eq!(headers["content-type"], "image/png"); |
| 11716 | 12000 | assert_eq!(bytes, b"png-bytes"); |
| 11717 | - let (status, _, _) = common::send_raw(&app, "GET", &uri, Some(&stranger), None, Vec::new()).await; | |
| 12001 | + let (status, _, _) = | |
| 12002 | + common::send_raw(&app, "GET", &uri, Some(&stranger), None, Vec::new()).await; | |
| 11718 | 12003 | assert_eq!(status, StatusCode::NOT_FOUND); |
| 11719 | 12004 | |
| 11720 | 12005 | // Approval freezes the image with the text: replace and remove both 409. |
| @@ -11734,9 +12019,17 @@ async fn question_pool_image_upload_and_freeze() { | ||
| 11734 | 12019 | assert_eq!(status, StatusCode::CONFLICT); |
| 11735 | 12020 | |
| 11736 | 12021 | // But the approved bytes are now school-wide, and ride the question meta. |
| 11737 | - let (status, _, _) = common::send_raw(&app, "GET", &uri, Some(&stranger), None, Vec::new()).await; | |
| 12022 | + let (status, _, _) = | |
| 12023 | + common::send_raw(&app, "GET", &uri, Some(&stranger), None, Vec::new()).await; | |
| 11738 | 12024 | assert_eq!(status, StatusCode::OK); |
| 11739 | - let res = send(&app, "GET", &format!("/questions/{qid}"), Some(&stranger), None).await; | |
| 12025 | + let res = send( | |
| 12026 | + &app, | |
| 12027 | + "GET", | |
| 12028 | + &format!("/questions/{qid}"), | |
| 12029 | + Some(&stranger), | |
| 12030 | + None, | |
| 12031 | + ) | |
| 12032 | + .await; | |
| 11740 | 12033 | assert_eq!(res.body["image"]["content_type"], "image/png"); |
| 11741 | 12034 | } |
| 11742 | 12035 | |
| @@ -11851,18 +12144,34 @@ async fn solution_images_edits_and_counts() { | ||
| 11851 | 12144 | // Question rows tally their solutions, in the list and the single GET. |
| 11852 | 12145 | let res = send(&app, "GET", "/questions?limit=5", Some(&asker), None).await; |
| 11853 | 12146 | assert_eq!(res.body["items"][0]["solution_count"], 1); |
| 11854 | - let res = send(&app, "GET", &format!("/questions/{qid}"), Some(&asker), None).await; | |
| 12147 | + let res = send( | |
| 12148 | + &app, | |
| 12149 | + "GET", | |
| 12150 | + &format!("/questions/{qid}"), | |
| 12151 | + Some(&asker), | |
| 12152 | + None, | |
| 12153 | + ) | |
| 12154 | + .await; | |
| 11855 | 12155 | assert_eq!(res.body["solution_count"], 1); |
| 11856 | 12156 | |
| 11857 | 12157 | // The author drops the photo; a second removal finds nothing. |
| 11858 | - let (status, _, _) = common::send_raw(&app, "DELETE", &uri, Some(&helper), None, Vec::new()).await; | |
| 12158 | + let (status, _, _) = | |
| 12159 | + common::send_raw(&app, "DELETE", &uri, Some(&helper), None, Vec::new()).await; | |
| 11859 | 12160 | assert_eq!(status, StatusCode::NO_CONTENT); |
| 11860 | 12161 | let (status, _, _) = common::send_raw(&app, "GET", &uri, Some(&asker), None, Vec::new()).await; |
| 11861 | 12162 | assert_eq!(status, StatusCode::NOT_FOUND); |
| 11862 | - let (status, _, _) = common::send_raw(&app, "DELETE", &uri, Some(&helper), None, Vec::new()).await; | |
| 12163 | + let (status, _, _) = | |
| 12164 | + common::send_raw(&app, "DELETE", &uri, Some(&helper), None, Vec::new()).await; | |
| 11863 | 12165 | assert_eq!(status, StatusCode::NOT_FOUND); |
| 11864 | 12166 | |
| 11865 | 12167 | // And the question delete still sweeps everything under it. |
| 11866 | - let res = send(&app, "DELETE", &format!("/questions/{qid}"), Some(&asker), None).await; | |
| 12168 | + let res = send( | |
| 12169 | + &app, | |
| 12170 | + "DELETE", | |
| 12171 | + &format!("/questions/{qid}"), | |
| 12172 | + Some(&asker), | |
| 12173 | + None, | |
| 12174 | + ) | |
| 12175 | + .await; | |
| 11867 | 12176 | assert_eq!(res.status, StatusCode::NO_CONTENT, "{}", res.body); |
| 11868 | 12177 | } |