Let students read the answer key in self-review
Browse files at this commite9ffc5ecc5d7a572e0895cf22c736e0ee239b2d6Parent: 4db4ff2- feat
- let students read the answer key in self-review
4 changed files +65 -4
- README.md +1 -0
- src/lib.rs +1 -1
- src/web/exams.rs +45 -3
- tests/integration.rs +18 -0
README.mdmodified+1 -0
| @@ -532,6 +532,7 @@ their existing shapes: the student exam-room reads | |||
| 532 | | GET | `/exams/{id}/students/{user}/attempts/{seq}/answers` | teacher | One prior sitting's answer sheet: `is_correct` flags + suggested `auto_score` (course manager) | | 532 | | GET | `/exams/{id}/students/{user}/attempts/{seq}/answers` | teacher | One prior sitting's answer sheet: `is_correct` flags + suggested `auto_score` (course manager) | |
| 533 | | GET | `/exams/{id}/students/{user}/attempts/{seq}/answers/{qid}/image` | teacher | One prior sitting's drawn-answer bytes, inline (course manager) | | 533 | | GET | `/exams/{id}/students/{user}/attempts/{seq}/answers/{qid}/image` | teacher | One prior sitting's drawn-answer bytes, inline (course manager) | |
| 534 | | GET | `/exams/{id}/students/{user}/marks` | teacher | A student's full per-sitting mark history, oldest first — the latest seq is the grade-of-record (course manager) | | 534 | | GET | `/exams/{id}/students/{user}/marks` | teacher | A student's full per-sitting mark history, oldest first — the latest seq is the grade-of-record (course manager) | |
| 535 | +| GET | `/exams/{id}/review/questions` | student | The exam's question list **with `correct`** — the answer key the caller checks their own sheet against (same review gate) · paged | | ||
| 535 | | GET | `/exams/{id}/review/attempts` | student | The caller's **own** sitting numbers (answers ⋃ marks), ascending — only when `allow_review` is on and the caller has been marked (`403`/`404` otherwise) | | 536 | | GET | `/exams/{id}/review/attempts` | student | The caller's **own** sitting numbers (answers ⋃ marks), ascending — only when `allow_review` is on and the caller has been marked (`403`/`404` otherwise) | |
| 536 | | GET | `/exams/{id}/review/attempts/{seq}/answers` | student | One of the caller's **own** sittings, judged: `is_correct` flags + suggested `auto_score` (same review gate) | | 537 | | GET | `/exams/{id}/review/attempts/{seq}/answers` | student | One of the caller's **own** sittings, judged: `is_correct` flags + suggested `auto_score` (same review gate) | |
| 537 | | GET | `/exams/{id}/review/attempts/{seq}/answers/{qid}/image` | student | The caller's **own** drawn-answer bytes for a sitting, inline (same review gate) | | 538 | | GET | `/exams/{id}/review/attempts/{seq}/answers/{qid}/image` | student | The caller's **own** drawn-answer bytes for a sitting, inline (same review gate) | |
src/lib.rsmodified+1 -1
| @@ -54,7 +54,7 @@ use crate::state::AppState; | |||
| 54 | (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"), | 54 | (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"), |
| 55 | (name = "questions", description = "The school question pool. Students ask (`POST /questions`, optionally attaching one photo of the problem via `POST /questions/{id}/image` — raster types only, ≤ the school's `max_file_bytes`, only while pending); teacher+ approve (`POST /questions/{id}/approve`) into the school-wide pool, or reject by deleting. Everyone student-and-up sees every approved question and may offer solutions under it (oldest first); parents stay out. Pending questions are visible only to their asker and to teacher+ (`GET /questions?status=pending` = the approval queue), and approval freezes title, body, and image — moderated content cannot be edited afterwards, only deleted (asker or teacher+; solutions and every image blob go with it). Solutions are the unmoderated half, so they never freeze: the author may edit the body (`PATCH /questions/{id}/solutions/{sid}` — author only, teacher+ included out; moderation stays delete-only) and attach/replace/remove one photo of the worked steps anytime (`/questions/{id}/solutions/{sid}/image`, same raster rules and size cap as the question's). Question rows carry a `solution_count`; solutions are deletable by their author or teacher+ (photo blob included)"), | 55 | (name = "questions", description = "The school question pool. Students ask (`POST /questions`, optionally attaching one photo of the problem via `POST /questions/{id}/image` — raster types only, ≤ the school's `max_file_bytes`, only while pending); teacher+ approve (`POST /questions/{id}/approve`) into the school-wide pool, or reject by deleting. Everyone student-and-up sees every approved question and may offer solutions under it (oldest first); parents stay out. Pending questions are visible only to their asker and to teacher+ (`GET /questions?status=pending` = the approval queue), and approval freezes title, body, and image — moderated content cannot be edited afterwards, only deleted (asker or teacher+; solutions and every image blob go with it). Solutions are the unmoderated half, so they never freeze: the author may edit the body (`PATCH /questions/{id}/solutions/{sid}` — author only, teacher+ included out; moderation stays delete-only) and attach/replace/remove one photo of the worked steps anytime (`/questions/{id}/solutions/{sid}/image`, same raster rules and size cap as the question's). Question rows carry a `solution_count`; solutions are deletable by their author or teacher+ (photo blob included)"), |
| 56 | (name = "attendance", description = "Attendance summary reports: event tallies + per-course lesson roll call with rates. Own report at `/me`; another user's needs teacher+ (teachers narrowed to their courses) or a parent link to that student"), | 56 | (name = "attendance", description = "Attendance summary reports: event tallies + per-course lesson roll call with rates. Own report at `/me`; another user's needs teacher+ (teachers narrowed to their courses) or a parent link to that student"), |
| 57 | - (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. Students mirror this on the answer side — one drawing per question inside their attempt (`POST /exams/{id}/attempt/answers/{qid}/image`, same raster types and size cap), saved like any answer through the writable-attempt gate and read back by the student (own) or a course manager (grading). Each sitting keeps its own answers, drawings, and mark keyed by the attempt `seq` — a retake starts from a blank sheet without erasing the prior one; the grading views show the latest sitting, a course manager reads any prior one via `GET /exams/{id}/students/{user}/attempts[/{seq}/answers]` (and the mark history at `.../marks`), and the latest seq is the grade-of-record. When the teacher turns on `allow_review`, a marked student reads back their own sittings through `GET /exams/{id}/review/attempts[/{seq}/answers[/{qid}/image]]` (own-scoped — never another student's, and only once an `ExamResult` proves they were marked). 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"), | 57 | + (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. Students mirror this on the answer side — one drawing per question inside their attempt (`POST /exams/{id}/attempt/answers/{qid}/image`, same raster types and size cap), saved like any answer through the writable-attempt gate and read back by the student (own) or a course manager (grading). Each sitting keeps its own answers, drawings, and mark keyed by the attempt `seq` — a retake starts from a blank sheet without erasing the prior one; the grading views show the latest sitting, a course manager reads any prior one via `GET /exams/{id}/students/{user}/attempts[/{seq}/answers]` (and the mark history at `.../marks`), and the latest seq is the grade-of-record. When the teacher turns on `allow_review`, a marked student reads back the answer key (`GET /exams/{id}/review/questions`, `correct` included) and their own sittings through `GET /exams/{id}/review/attempts[/{seq}/answers[/{qid}/image]]` (own-scoped — never another student's, and only once an `ExamResult` proves they were marked). 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"), |
| 58 | (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"), | 58 | (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"), |
| 59 | (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). An exam kind whose exams already carry marks cannot be removed from the list (409) — those marks would silently re-weight. Read: any authenticated user; edit: manager+"), | 59 | (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). An exam kind whose exams already carry marks cannot be removed from the list (409) — those marks would silently re-weight. Read: any authenticated user; edit: manager+"), |
| 60 | (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"), | 60 | (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"), |
src/web/exams.rsmodified+45 -3
| @@ -82,6 +82,7 @@ pub fn routes() -> OpenApiRouter<AppState> { | |||
| 82 | .routes(routes!(student_attempts)) | 82 | .routes(routes!(student_attempts)) |
| 83 | .routes(routes!(student_attempt_answers)) | 83 | .routes(routes!(student_attempt_answers)) |
| 84 | .routes(routes!(student_marks_history)) | 84 | .routes(routes!(student_marks_history)) |
| 85 | + .routes(routes!(review_questions)) | ||
| 85 | .routes(routes!(review_attempts)) | 86 | .routes(routes!(review_attempts)) |
| 86 | .routes(routes!(review_attempt_answers)) | 87 | .routes(routes!(review_attempt_answers)) |
| 87 | // The image routes get their own HTTP body cap, like the note-file | 88 | // The image routes get their own HTTP body cap, like the note-file |
| @@ -1563,8 +1564,20 @@ async fn list_questions( | |||
| 1563 | "only the course creator, an assigned teacher, or a manager/admin can read the question list", | 1564 | "only the course creator, an assigned teacher, or a manager/admin can read the question list", |
| 1564 | )); | 1565 | )); |
| 1565 | } | 1566 | } |
| 1566 | - let questions = ExamQuestion::list_for_exam(exam.get_id(), &st.db).await?; | 1567 | + Ok(Json(question_page(&exam, limit, offset, &st.db).await?)) |
| 1567 | - let images = images_by_question(exam.get_id(), &st.db).await?; | 1568 | +} |
| 1569 | + | ||
| 1570 | +/// The paged answer-key list (`correct` included) shared by the teacher | ||
| 1571 | +/// `list_questions` read and the student `review_questions` read — the two | ||
| 1572 | +/// differ only in the access wall they run first. | ||
| 1573 | +async fn question_page( | ||
| 1574 | + exam: &Exam, | ||
| 1575 | + limit: Option<i64>, | ||
| 1576 | + offset: i64, | ||
| 1577 | + db: &Database, | ||
| 1578 | +) -> Result<Page<QuestionResponse>, AppError> { | ||
| 1579 | + let questions = ExamQuestion::list_for_exam(exam.get_id(), db).await?; | ||
| 1580 | + let images = images_by_question(exam.get_id(), db).await?; | ||
| 1568 | let total = questions.len() as i64; | 1581 | let total = questions.len() as i64; |
| 1569 | let items = paginate(&questions, limit, offset) | 1582 | let items = paginate(&questions, limit, offset) |
| 1570 | .iter() | 1583 | .iter() |
| @@ -1577,7 +1590,7 @@ async fn list_questions( | |||
| 1577 | ) | 1590 | ) |
| 1578 | }) | 1591 | }) |
| 1579 | .collect(); | 1592 | .collect(); |
| 1580 | - Ok(Json(Page::new(items, total, limit, offset))) | 1593 | + Ok(Page::new(items, total, limit, offset)) |
| 1581 | } | 1594 | } |
| 1582 | 1595 | ||
| 1583 | /// Edit a question. Requires teacher+ and management rights over the exam's | 1596 | /// Edit a question. Requires teacher+ and management rights over the exam's |
| @@ -3014,6 +3027,35 @@ async fn review_attempts( | |||
| 3014 | Ok(Json(seqs)) | 3027 | Ok(Json(seqs)) |
| 3015 | } | 3028 | } |
| 3016 | 3029 | ||
| 3030 | +/// The exam's full question list, `correct` indexes included — the answer key | ||
| 3031 | +/// the caller reviews their own sheet against. Same review gate as the other | ||
| 3032 | +/// self-review reads; revealing `correct` is the point (the gate already proves | ||
| 3033 | +/// the caller was marked). Paged via `?limit=&offset=`. | ||
| 3034 | +#[utoipa::path( | ||
| 3035 | + get, | ||
| 3036 | + path = "/{id}/review/questions", | ||
| 3037 | + tag = "exams", | ||
| 3038 | + security(("session_cookie" = [])), | ||
| 3039 | + params(("id" = String, Path, description = "Exam id"), PageParams), | ||
| 3040 | + responses( | ||
| 3041 | + (status = 200, description = "A page of the exam's questions with `correct` (all of them when unpaged)", body = Page<QuestionResponse>), | ||
| 3042 | + (status = 400, description = "Invalid limit or offset", body = ErrorResponse), | ||
| 3043 | + (status = 401, description = "Not authenticated", body = ErrorResponse), | ||
| 3044 | + (status = 403, description = "Review not enabled for this exam", body = ErrorResponse), | ||
| 3045 | + (status = 404, description = "Exam not found, still a draft, or the caller has no mark on it", body = ErrorResponse), | ||
| 3046 | + ), | ||
| 3047 | +)] | ||
| 3048 | +async fn review_questions( | ||
| 3049 | + State(st): State<AppState>, | ||
| 3050 | + CurrentUser(user): CurrentUser, | ||
| 3051 | + Path(id): Path<String>, | ||
| 3052 | + Query(page): Query<PageParams>, | ||
| 3053 | +) -> Result<Json<Page<QuestionResponse>>, AppError> { | ||
| 3054 | + let (limit, offset) = page.resolve()?; | ||
| 3055 | + let exam = reviewable_exam(&st, &user, &id).await?; | ||
| 3056 | + Ok(Json(question_page(&exam, limit, offset, &st.db).await?)) | ||
| 3057 | +} | ||
| 3058 | + | ||
| 3017 | /// One of the caller's own sittings, judged — the `seq`th attempt's answers, | 3059 | /// One of the caller's own sittings, judged — the `seq`th attempt's answers, |
| 3018 | /// drawing refs, correctness flags, and auto-score suggestion. Own-scoped | 3060 | /// drawing refs, correctness flags, and auto-score suggestion. Own-scoped |
| 3019 | /// review view. | 3061 | /// review view. |
tests/integration.rsmodified+18 -0
| @@ -16511,6 +16511,24 @@ async fn self_review_returns_own_seqs_and_per_sitting_answers() { | |||
| 16511 | assert_eq!(seq1.status, StatusCode::OK, "{}", seq1.body); | 16511 | assert_eq!(seq1.status, StatusCode::OK, "{}", seq1.body); |
| 16512 | assert_eq!(seq1.body["answers"][0]["text"], "mitochondria"); | 16512 | assert_eq!(seq1.body["answers"][0]["text"], "mitochondria"); |
| 16513 | assert_eq!(seq2.body["answers"][0]["text"], "chloroplast"); | 16513 | assert_eq!(seq2.body["answers"][0]["text"], "chloroplast"); |
| 16514 | + | ||
| 16515 | + // The answer key: a marked student reads the questions with `correct` | ||
| 16516 | + // exposed (the whole point of review) — the same list the teacher sees. | ||
| 16517 | + let key = send( | ||
| 16518 | + &app, | ||
| 16519 | + "GET", | ||
| 16520 | + &format!("/exams/{exam}/review/questions"), | ||
| 16521 | + Some(&student), | ||
| 16522 | + None, | ||
| 16523 | + ) | ||
| 16524 | + .await; | ||
| 16525 | + assert_eq!(key.status, StatusCode::OK, "{}", key.body); | ||
| 16526 | + assert_eq!(key.body["items"][0]["id"], question); | ||
| 16527 | + assert!( | ||
| 16528 | + key.body["items"][0].as_object().unwrap().contains_key("correct"), | ||
| 16529 | + "review/questions must expose `correct`: {}", | ||
| 16530 | + key.body | ||
| 16531 | + ); | ||
| 16514 | } | 16532 | } |
| 16515 | 16533 | ||
| 16516 | /// Own-scoped isolation: two graded students, review on. There is no `{user}` | 16534 | /// Own-scoped isolation: two graded students, review on. There is no `{user}` |