From da6198f5f1bf59a897eadba3f9c1697beff56204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 24 Jul 2026 06:16:48 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(exams):=20student=20self-revie?= =?UTF-8?q?w=20of=20own=20graded=20exam?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sync with backend: a per-exam teacher toggle `allow_review` (mirrors `allow_rejoin` in the exam form) and a student-facing review of their own paper + past attempts, shown in the "your result" tab once the exam is marked and review is enabled. - allow_review wired through Exam type, create/patch bodies, and the exam-settings form (checkbox + tr/en strings). - Four self-scoped API calls (/exams/{id}/review/questions|attempts| attempts/{seq}/answers|.../image); AnswerSheetView gains a mode:"grader"|"self" prop that swaps the API layer while reusing the same render (seq picker, right/wrong, drawing playback). - Fix: the ownResult tab was gated on !isScheduled(), which is never true for a moded exam (isSittableExam is mode-based), so it never rendered. Gate it on ownResult() instead — the result exists only after marking, which is exactly the intended condition. Browser-verified end to end: toggle on -> review renders questions + answers + drawing playback (200s); toggle off -> mark shown, review hidden, no stray calls; no console errors. --- docs/role-scope-matrix.md | 2 ++ src/api/client/types.ts | 1 + src/api/courses/postCourseExam.ts | 1 + .../exams/getExamReviewAttemptAnswerImage.ts | 11 ++++++++ src/api/exams/getExamReviewAttemptAnswers.ts | 14 ++++++++++ src/api/exams/getExamReviewAttempts.ts | 6 +++++ src/api/exams/getExamReviewQuestions.ts | 16 ++++++++++++ src/api/exams/index.ts | 4 +++ src/api/exams/patchExamById.ts | 1 + src/components/exams/answer-sheet-view.tsx | 26 ++++++++++++++----- src/components/exams/exam-form.tsx | 16 ++++++++++++ src/i18n/messages.ts | 6 +++++ src/pages/exam-detail-page.tsx | 10 ++++--- 13 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 src/api/exams/getExamReviewAttemptAnswerImage.ts create mode 100644 src/api/exams/getExamReviewAttemptAnswers.ts create mode 100644 src/api/exams/getExamReviewAttempts.ts create mode 100644 src/api/exams/getExamReviewQuestions.ts diff --git a/docs/role-scope-matrix.md b/docs/role-scope-matrix.md index 2c2f645..ae7b3ad 100644 --- a/docs/role-scope-matrix.md +++ b/docs/role-scope-matrix.md @@ -75,6 +75,8 @@ | Grade students | ❌ | ✅ (course manager) | ✅ | ✅ | | Read exam results / statistics | ❌ | ✅ (course manager) | ✅ | ✅ | | Read own exam result | ✅ | ❌ (FE) | ❌ (FE) | ❌ (FE) | + + | Write exam questions | ❌ | ✅ (course manager) | ✅ | ✅ | | Start / finish own pomodoro focus session | ✅ | ❌ | ❌ | ❌ | | Read answer sheets | ❌ | ✅ (course manager) | ✅ | ✅ | diff --git a/src/api/client/types.ts b/src/api/client/types.ts index ba08ff4..83ca367 100644 --- a/src/api/client/types.ts +++ b/src/api/client/types.ts @@ -144,6 +144,7 @@ export type Exam = { duration_ms: number | null; max_attempts: number; allow_rejoin: boolean; + allow_review: boolean; draft: boolean; }; diff --git a/src/api/courses/postCourseExam.ts b/src/api/courses/postCourseExam.ts index 3a76595..c8a9fa6 100644 --- a/src/api/courses/postCourseExam.ts +++ b/src/api/courses/postCourseExam.ts @@ -11,6 +11,7 @@ export type PostCourseExamBody = { duration_ms?: number | null; max_attempts?: number | null; allow_rejoin?: boolean | null; + allow_review?: boolean | null; draft?: boolean | null; }; diff --git a/src/api/exams/getExamReviewAttemptAnswerImage.ts b/src/api/exams/getExamReviewAttemptAnswerImage.ts new file mode 100644 index 0000000..c61702f --- /dev/null +++ b/src/api/exams/getExamReviewAttemptAnswerImage.ts @@ -0,0 +1,11 @@ +import { blobClient } from "../client"; + +/** Self-review of one of the caller's own past sitting's answer images, scoped to a seq. */ +export async function getExamReviewAttemptAnswerImage( + examId: string, + seq: number, + questionId: string, + signal?: AbortSignal, +): Promise { + return blobClient(`/exams/${examId}/review/attempts/${seq}/answers/${questionId}/image`, signal); +} diff --git a/src/api/exams/getExamReviewAttemptAnswers.ts b/src/api/exams/getExamReviewAttemptAnswers.ts new file mode 100644 index 0000000..19f2ce0 --- /dev/null +++ b/src/api/exams/getExamReviewAttemptAnswers.ts @@ -0,0 +1,14 @@ +import { client } from "@/api/client"; +import type { StudentAnswerSheet } from "@/api/client"; + +/** Self-review of one of the caller's own past sittings (same shape as the current attempt). */ +export async function getExamReviewAttemptAnswers( + examId: string, + seq: number, + signal?: AbortSignal, +): Promise { + return client( + `/exams/${encodeURIComponent(examId)}/review/attempts/${seq}/answers`, + { signal }, + ); +} diff --git a/src/api/exams/getExamReviewAttempts.ts b/src/api/exams/getExamReviewAttempts.ts new file mode 100644 index 0000000..5678d13 --- /dev/null +++ b/src/api/exams/getExamReviewAttempts.ts @@ -0,0 +1,6 @@ +import { client } from "@/api/client"; + +/** Sitting seqs the caller has for this exam, ascending (e.g. [1, 2]). Self-review; needs allow_review + marked. */ +export async function getExamReviewAttempts(examId: string, signal?: AbortSignal): Promise { + return client(`/exams/${encodeURIComponent(examId)}/review/attempts`, { signal }); +} diff --git a/src/api/exams/getExamReviewQuestions.ts b/src/api/exams/getExamReviewQuestions.ts new file mode 100644 index 0000000..f781d37 --- /dev/null +++ b/src/api/exams/getExamReviewQuestions.ts @@ -0,0 +1,16 @@ +import { client } from "@/api/client"; +import { normalizePage, pageQuery, type Page, type PageParams } from "@/api/client"; +import type { ExamQuestion } from "@/api/client"; + +/** Self-review question list (with the correct-answer key) for an exam the caller has been marked on. */ +export async function getExamReviewQuestions( + examId: string, + params?: PageParams, + signal?: AbortSignal, +): Promise> { + const data = await client( + `/exams/${encodeURIComponent(examId)}/review/questions${pageQuery(params)}`, + { signal }, + ); + return normalizePage(data); +} diff --git a/src/api/exams/index.ts b/src/api/exams/index.ts index 8ed4473..570188c 100644 --- a/src/api/exams/index.ts +++ b/src/api/exams/index.ts @@ -30,4 +30,8 @@ export * from "./getStudentAnswerImage"; export * from "./getStudentAttempts"; export * from "./getStudentAttemptAnswers"; export * from "./getStudentAttemptAnswerImage"; +export * from "./getExamReviewQuestions"; +export * from "./getExamReviewAttempts"; +export * from "./getExamReviewAttemptAnswers"; +export * from "./getExamReviewAttemptAnswerImage"; export * from "./getStudentMarksHistory"; diff --git a/src/api/exams/patchExamById.ts b/src/api/exams/patchExamById.ts index ec93f04..97e74f9 100644 --- a/src/api/exams/patchExamById.ts +++ b/src/api/exams/patchExamById.ts @@ -11,6 +11,7 @@ export type PatchExamBody = { duration_ms?: number | null; max_attempts?: number | null; allow_rejoin?: boolean | null; + allow_review?: boolean | null; draft?: boolean | null; }; diff --git a/src/components/exams/answer-sheet-view.tsx b/src/components/exams/answer-sheet-view.tsx index b40e8ff..8321555 100644 --- a/src/components/exams/answer-sheet-view.tsx +++ b/src/components/exams/answer-sheet-view.tsx @@ -1,8 +1,9 @@ import { For, Show, Suspense, createMemo, createResource, createSignal, useTransition } from "solid-js"; import { ApiError } from "@/api/client"; -import { getExamQuestions } from "@/api/exams"; +import { getExamQuestions, getExamReviewQuestions } from "@/api/exams"; import { getStudentAnswers, getStudentAnswerImage } from "@/api/exams"; import { getStudentAttempts, getStudentAttemptAnswers, getStudentAttemptAnswerImage } from "@/api/exams"; +import { getExamReviewAttempts, getExamReviewAttemptAnswers, getExamReviewAttemptAnswerImage } from "@/api/exams"; import type { StudentAnswerSheet } from "@/api/client"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; @@ -15,8 +16,11 @@ import { joinAnswerSheet } from "@/lib/answer-sheet"; import { personLabelWithId } from "@/lib/person"; import { useT } from "@/stores/preferences-context"; -export function AnswerSheetView(props: { examId: string; userId: string }) { +export function AnswerSheetView(props: { examId: string; userId: string; mode?: "grader" | "self" }) { const t = useT(); + // "grader" hits the teacher, userId-scoped routes; "self" hits the self-scoped + // /review routes (no userId in path). Everything below is identical either way. + const mode = () => props.mode ?? "grader"; // Which sitting the grader is viewing. null = the latest (grade-of-record), the default. const [selectedSeq, setSelectedSeq] = createSignal(null); @@ -31,7 +35,7 @@ export function AnswerSheetView(props: { examId: string; userId: string }) { () => [props.examId, props.userId] as const, async ([examId, userId]) => { try { - return await getStudentAttempts(examId, userId); + return mode() === "self" ? await getExamReviewAttempts(examId) : await getStudentAttempts(examId, userId); } catch (err) { if (err instanceof ApiError && err.status === 404) return [] as number[]; throw err; @@ -59,12 +63,15 @@ export function AnswerSheetView(props: { examId: string; userId: string }) { const answerImageUrl = (questionId: string) => { const seq = activeSeq(); + if (mode() === "self") + return `/api/exams/${props.examId}/review/attempts/${seq}/answers/${questionId}/image`; return isLatest() || seq == null ? `/api/exams/${props.examId}/attempts/${props.userId}/answers/${questionId}/image` : `/api/exams/${props.examId}/students/${props.userId}/attempts/${seq}/answers/${questionId}/image`; }; const fetchAnswerImage = (questionId: string) => { const seq = activeSeq(); + if (mode() === "self") return getExamReviewAttemptAnswerImage(props.examId, seq ?? 1, questionId); return isLatest() || seq == null ? getStudentAnswerImage(props.examId, props.userId, questionId) : getStudentAttemptAnswerImage(props.examId, props.userId, seq, questionId); @@ -75,12 +82,17 @@ export function AnswerSheetView(props: { examId: string; userId: string }) { // (unchanged from before); an older seq uses the per-seq history route. () => [props.examId, props.userId, activeSeq(), isLatest()] as const, async ([examId, userId, seq, latest]) => { - const questions = await getExamQuestions(examId); + const questions = mode() === "self" ? await getExamReviewQuestions(examId) : await getExamQuestions(examId); let sheet: StudentAnswerSheet; try { - sheet = latest || seq == null - ? await getStudentAnswers(examId, userId) - : await getStudentAttemptAnswers(examId, userId, seq); + if (mode() === "self") { + if (seq == null) throw new ApiError(404, "no attempts"); + sheet = await getExamReviewAttemptAnswers(examId, seq); + } else { + sheet = latest || seq == null + ? await getStudentAnswers(examId, userId) + : await getStudentAttemptAnswers(examId, userId, seq); + } } catch (err) { if (err instanceof ApiError && err.status === 404) { sheet = { diff --git a/src/components/exams/exam-form.tsx b/src/components/exams/exam-form.tsx index 8aa8d5c..3e1f55f 100644 --- a/src/components/exams/exam-form.tsx +++ b/src/components/exams/exam-form.tsx @@ -63,6 +63,7 @@ export type ExamFormValues = { duration_ms: number | null; max_attempts: number; allow_rejoin: boolean; + allow_review: boolean; draft: boolean; }; @@ -80,6 +81,7 @@ export function ExamForm(props: { const [hasRetakes, setHasRetakes] = createSignal((props.initial?.max_attempts ?? 1) !== 1); const [maxAttempts, setMaxAttempts] = createSignal(String(props.initial?.max_attempts ?? 1)); const [allowRejoin, setAllowRejoin] = createSignal(props.initial?.allow_rejoin ?? true); + const [allowReview, setAllowReview] = createSignal(props.initial?.allow_review ?? false); const [draft, setDraft] = createSignal(props.initial?.draft ?? false); const [startsDate, setStartsDate] = createSignal(dateInputFromMs(props.initial?.starts_at)); const [startsTime, setStartsTime] = createSignal(timeInputFromMs(props.initial?.starts_at)); @@ -188,6 +190,7 @@ export function ExamForm(props: { duration_ms, max_attempts: hasRetakes() ? Number(maxAttempts()) : 1, allow_rejoin: allowRejoin(), + allow_review: allowReview(), draft: draft(), } satisfies ExamFormValues; @@ -395,6 +398,19 @@ export function ExamForm(props: { + +