forge
Explore
Log in

Don't you dare go Hollow

Student self-review of own graded exam

Browse files at this commit

da6198f5f1bf59a897eadba3f9c1697beff56204Ahmet Kaan GümüşParent: b085a74
  • feat
    • student self-review of own graded exam
Show full message
✨ feat(exams): student self-review of own graded exam

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.mdmodified+2 -0
@@ -75,6 +75,8 @@
75 | Grade students | ❌ | ✅ (course manager) | ✅ | ✅ |75 | Grade students | ❌ | ✅ (course manager) | ✅ | ✅ |
76 | Read exam results / statistics | ❌ | ✅ (course manager) | ✅ | ✅ |76 | Read exam results / statistics | ❌ | ✅ (course manager) | ✅ | ✅ |
77 | Read own exam result | ✅ | ❌ (FE) | ❌ (FE) | ❌ (FE) |77 | Read own exam result | ✅ | ❌ (FE) | ❌ (FE) | ❌ (FE) |
78+<!-- Own-result review (own answer sheet + past attempts) is additionally gated on the exam's `allow_review` flag AND the teacher having marked the student. -->
79+
78 | Write exam questions | ❌ | ✅ (course manager) | ✅ | ✅ |80 | Write exam questions | ❌ | ✅ (course manager) | ✅ | ✅ |
79 | Start / finish own pomodoro focus session | ✅ | ❌ | ❌ | ❌ |81 | Start / finish own pomodoro focus session | ✅ | ❌ | ❌ | ❌ |
80 | Read answer sheets | ❌ | ✅ (course manager) | ✅ | ✅ |82 | Read answer sheets | ❌ | ✅ (course manager) | ✅ | ✅ |
src/api/client/types.tsmodified+1 -0
@@ -144,6 +144,7 @@ export type Exam = {
144 duration_ms: number | null;144 duration_ms: number | null;
145 max_attempts: number;145 max_attempts: number;
146 allow_rejoin: boolean;146 allow_rejoin: boolean;
147+ allow_review: boolean;
147 draft: boolean;148 draft: boolean;
148 };149 };
149 150
src/api/courses/postCourseExam.tsmodified+1 -0
@@ -11,6 +11,7 @@ export type PostCourseExamBody = {
11 duration_ms?: number | null;11 duration_ms?: number | null;
12 max_attempts?: number | null;12 max_attempts?: number | null;
13 allow_rejoin?: boolean | null;13 allow_rejoin?: boolean | null;
14+ allow_review?: boolean | null;
14 draft?: boolean | null;15 draft?: boolean | null;
15 };16 };
16 17
src/api/exams/getExamReviewAttemptAnswerImage.tsadded+11 -0
@@ -0,0 +1,11 @@
1+import { blobClient } from "../client";
2+
3+/** Self-review of one of the caller's own past sitting's answer images, scoped to a seq. */
4+export async function getExamReviewAttemptAnswerImage(
5+ examId: string,
6+ seq: number,
7+ questionId: string,
8+ signal?: AbortSignal,
9+): Promise<Blob> {
10+ return blobClient(`/exams/${examId}/review/attempts/${seq}/answers/${questionId}/image`, signal);
11+}
src/api/exams/getExamReviewAttemptAnswers.tsadded+14 -0
@@ -0,0 +1,14 @@
1+import { client } from "@/api/client";
2+import type { StudentAnswerSheet } from "@/api/client";
3+
4+/** Self-review of one of the caller's own past sittings (same shape as the current attempt). */
5+export async function getExamReviewAttemptAnswers(
6+ examId: string,
7+ seq: number,
8+ signal?: AbortSignal,
9+): Promise<StudentAnswerSheet> {
10+ return client<StudentAnswerSheet>(
11+ `/exams/${encodeURIComponent(examId)}/review/attempts/${seq}/answers`,
12+ { signal },
13+ );
14+}
src/api/exams/getExamReviewAttempts.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "@/api/client";
2+
3+/** Sitting seqs the caller has for this exam, ascending (e.g. [1, 2]). Self-review; needs allow_review + marked. */
4+export async function getExamReviewAttempts(examId: string, signal?: AbortSignal): Promise<number[]> {
5+ return client<number[]>(`/exams/${encodeURIComponent(examId)}/review/attempts`, { signal });
6+}
src/api/exams/getExamReviewQuestions.tsadded+16 -0
@@ -0,0 +1,16 @@
1+import { client } from "@/api/client";
2+import { normalizePage, pageQuery, type Page, type PageParams } from "@/api/client";
3+import type { ExamQuestion } from "@/api/client";
4+
5+/** Self-review question list (with the correct-answer key) for an exam the caller has been marked on. */
6+export async function getExamReviewQuestions(
7+ examId: string,
8+ params?: PageParams,
9+ signal?: AbortSignal,
10+): Promise<Page<ExamQuestion>> {
11+ const data = await client<unknown>(
12+ `/exams/${encodeURIComponent(examId)}/review/questions${pageQuery(params)}`,
13+ { signal },
14+ );
15+ return normalizePage<ExamQuestion>(data);
16+}
src/api/exams/index.tsmodified+4 -0
@@ -30,4 +30,8 @@ export * from "./getStudentAnswerImage";
30 export * from "./getStudentAttempts";30 export * from "./getStudentAttempts";
31 export * from "./getStudentAttemptAnswers";31 export * from "./getStudentAttemptAnswers";
32 export * from "./getStudentAttemptAnswerImage";32 export * from "./getStudentAttemptAnswerImage";
33+export * from "./getExamReviewQuestions";
34+export * from "./getExamReviewAttempts";
35+export * from "./getExamReviewAttemptAnswers";
36+export * from "./getExamReviewAttemptAnswerImage";
33 export * from "./getStudentMarksHistory";37 export * from "./getStudentMarksHistory";
src/api/exams/patchExamById.tsmodified+1 -0
@@ -11,6 +11,7 @@ export type PatchExamBody = {
11 duration_ms?: number | null;11 duration_ms?: number | null;
12 max_attempts?: number | null;12 max_attempts?: number | null;
13 allow_rejoin?: boolean | null;13 allow_rejoin?: boolean | null;
14+ allow_review?: boolean | null;
14 draft?: boolean | null;15 draft?: boolean | null;
15 };16 };
16 17
src/components/exams/answer-sheet-view.tsxmodified+19 -7
@@ -1,8 +1,9 @@
1 import { For, Show, Suspense, createMemo, createResource, createSignal, useTransition } from "solid-js";1 import { For, Show, Suspense, createMemo, createResource, createSignal, useTransition } from "solid-js";
2 import { ApiError } from "@/api/client";2 import { ApiError } from "@/api/client";
3-import { getExamQuestions } from "@/api/exams";3+import { getExamQuestions, getExamReviewQuestions } from "@/api/exams";
4 import { getStudentAnswers, getStudentAnswerImage } from "@/api/exams";4 import { getStudentAnswers, getStudentAnswerImage } from "@/api/exams";
5 import { getStudentAttempts, getStudentAttemptAnswers, getStudentAttemptAnswerImage } from "@/api/exams";5 import { getStudentAttempts, getStudentAttemptAnswers, getStudentAttemptAnswerImage } from "@/api/exams";
6+import { getExamReviewAttempts, getExamReviewAttemptAnswers, getExamReviewAttemptAnswerImage } from "@/api/exams";
6 import type { StudentAnswerSheet } from "@/api/client";7 import type { StudentAnswerSheet } from "@/api/client";
7 import { Badge } from "@/components/ui/badge";8 import { Badge } from "@/components/ui/badge";
8 import { Button } from "@/components/ui/button";9 import { Button } from "@/components/ui/button";
@@ -15,8 +16,11 @@ import { joinAnswerSheet } from "@/lib/answer-sheet";
15 import { personLabelWithId } from "@/lib/person";16 import { personLabelWithId } from "@/lib/person";
16 import { useT } from "@/stores/preferences-context";17 import { useT } from "@/stores/preferences-context";
17 18
18-export function AnswerSheetView(props: { examId: string; userId: string }) {19+export function AnswerSheetView(props: { examId: string; userId: string; mode?: "grader" | "self" }) {
19 const t = useT();20 const t = useT();
21+ // "grader" hits the teacher, userId-scoped routes; "self" hits the self-scoped
22+ // /review routes (no userId in path). Everything below is identical either way.
23+ const mode = () => props.mode ?? "grader";
20 24
21 // Which sitting the grader is viewing. null = the latest (grade-of-record), the default.25 // Which sitting the grader is viewing. null = the latest (grade-of-record), the default.
22 const [selectedSeq, setSelectedSeq] = createSignal<number | null>(null);26 const [selectedSeq, setSelectedSeq] = createSignal<number | null>(null);
@@ -31,7 +35,7 @@ export function AnswerSheetView(props: { examId: string; userId: string }) {
31 () => [props.examId, props.userId] as const,35 () => [props.examId, props.userId] as const,
32 async ([examId, userId]) => {36 async ([examId, userId]) => {
33 try {37 try {
34- return await getStudentAttempts(examId, userId);38+ return mode() === "self" ? await getExamReviewAttempts(examId) : await getStudentAttempts(examId, userId);
35 } catch (err) {39 } catch (err) {
36 if (err instanceof ApiError && err.status === 404) return [] as number[];40 if (err instanceof ApiError && err.status === 404) return [] as number[];
37 throw err;41 throw err;
@@ -59,12 +63,15 @@ export function AnswerSheetView(props: { examId: string; userId: string }) {
59 63
60 const answerImageUrl = (questionId: string) => {64 const answerImageUrl = (questionId: string) => {
61 const seq = activeSeq();65 const seq = activeSeq();
66+ if (mode() === "self")
67+ return `/api/exams/${props.examId}/review/attempts/${seq}/answers/${questionId}/image`;
62 return isLatest() || seq == null68 return isLatest() || seq == null
63 ? `/api/exams/${props.examId}/attempts/${props.userId}/answers/${questionId}/image`69 ? `/api/exams/${props.examId}/attempts/${props.userId}/answers/${questionId}/image`
64 : `/api/exams/${props.examId}/students/${props.userId}/attempts/${seq}/answers/${questionId}/image`;70 : `/api/exams/${props.examId}/students/${props.userId}/attempts/${seq}/answers/${questionId}/image`;
65 };71 };
66 const fetchAnswerImage = (questionId: string) => {72 const fetchAnswerImage = (questionId: string) => {
67 const seq = activeSeq();73 const seq = activeSeq();
74+ if (mode() === "self") return getExamReviewAttemptAnswerImage(props.examId, seq ?? 1, questionId);
68 return isLatest() || seq == null75 return isLatest() || seq == null
69 ? getStudentAnswerImage(props.examId, props.userId, questionId)76 ? getStudentAnswerImage(props.examId, props.userId, questionId)
70 : getStudentAttemptAnswerImage(props.examId, props.userId, seq, questionId);77 : getStudentAttemptAnswerImage(props.examId, props.userId, seq, questionId);
@@ -75,12 +82,17 @@ export function AnswerSheetView(props: { examId: string; userId: string }) {
75 // (unchanged from before); an older seq uses the per-seq history route.82 // (unchanged from before); an older seq uses the per-seq history route.
76 () => [props.examId, props.userId, activeSeq(), isLatest()] as const,83 () => [props.examId, props.userId, activeSeq(), isLatest()] as const,
77 async ([examId, userId, seq, latest]) => {84 async ([examId, userId, seq, latest]) => {
78- const questions = await getExamQuestions(examId);85+ const questions = mode() === "self" ? await getExamReviewQuestions(examId) : await getExamQuestions(examId);
79 let sheet: StudentAnswerSheet;86 let sheet: StudentAnswerSheet;
80 try {87 try {
81- sheet = latest || seq == null88+ if (mode() === "self") {
82- ? await getStudentAnswers(examId, userId)89+ if (seq == null) throw new ApiError(404, "no attempts");
83- : await getStudentAttemptAnswers(examId, userId, seq);90+ sheet = await getExamReviewAttemptAnswers(examId, seq);
91+ } else {
92+ sheet = latest || seq == null
93+ ? await getStudentAnswers(examId, userId)
94+ : await getStudentAttemptAnswers(examId, userId, seq);
95+ }
84 } catch (err) {96 } catch (err) {
85 if (err instanceof ApiError && err.status === 404) {97 if (err instanceof ApiError && err.status === 404) {
86 sheet = {98 sheet = {
src/components/exams/exam-form.tsxmodified+16 -0
@@ -63,6 +63,7 @@ export type ExamFormValues = {
63 duration_ms: number | null;63 duration_ms: number | null;
64 max_attempts: number;64 max_attempts: number;
65 allow_rejoin: boolean;65 allow_rejoin: boolean;
66+ allow_review: boolean;
66 draft: boolean;67 draft: boolean;
67 };68 };
68 69
@@ -80,6 +81,7 @@ export function ExamForm(props: {
80 const [hasRetakes, setHasRetakes] = createSignal((props.initial?.max_attempts ?? 1) !== 1);81 const [hasRetakes, setHasRetakes] = createSignal((props.initial?.max_attempts ?? 1) !== 1);
81 const [maxAttempts, setMaxAttempts] = createSignal(String(props.initial?.max_attempts ?? 1));82 const [maxAttempts, setMaxAttempts] = createSignal(String(props.initial?.max_attempts ?? 1));
82 const [allowRejoin, setAllowRejoin] = createSignal(props.initial?.allow_rejoin ?? true);83 const [allowRejoin, setAllowRejoin] = createSignal(props.initial?.allow_rejoin ?? true);
84+ const [allowReview, setAllowReview] = createSignal(props.initial?.allow_review ?? false);
83 const [draft, setDraft] = createSignal(props.initial?.draft ?? false);85 const [draft, setDraft] = createSignal(props.initial?.draft ?? false);
84 const [startsDate, setStartsDate] = createSignal(dateInputFromMs(props.initial?.starts_at));86 const [startsDate, setStartsDate] = createSignal(dateInputFromMs(props.initial?.starts_at));
85 const [startsTime, setStartsTime] = createSignal(timeInputFromMs(props.initial?.starts_at));87 const [startsTime, setStartsTime] = createSignal(timeInputFromMs(props.initial?.starts_at));
@@ -188,6 +190,7 @@ export function ExamForm(props: {
188 duration_ms,190 duration_ms,
189 max_attempts: hasRetakes() ? Number(maxAttempts()) : 1,191 max_attempts: hasRetakes() ? Number(maxAttempts()) : 1,
190 allow_rejoin: allowRejoin(),192 allow_rejoin: allowRejoin(),
193+ allow_review: allowReview(),
191 draft: draft(),194 draft: draft(),
192 } satisfies ExamFormValues;195 } satisfies ExamFormValues;
193 196
@@ -395,6 +398,19 @@ export function ExamForm(props: {
395 </div>398 </div>
396 </label>399 </label>
397 400
401+ <label class="flex items-start gap-2 rounded-xl border bg-background/60 px-3 py-2 text-sm">
402+ <input
403+ type="checkbox"
404+ class="mt-0.5 h-4 w-4 shrink-0 rounded border-border"
405+ checked={allowReview()}
406+ onChange={(e) => setAllowReview(e.currentTarget.checked)}
407+ />
408+ <div>
409+ <span class="font-medium">{t("exams.allowReview")}</span>
410+ <p class="text-xs font-normal text-muted-foreground">{t("exams.allowReviewHelp")}</p>
411+ </div>
412+ </label>
413+
398 <label class="flex items-start gap-2 rounded-xl border bg-background/60 px-3 py-2 text-sm">414 <label class="flex items-start gap-2 rounded-xl border bg-background/60 px-3 py-2 text-sm">
399 <input415 <input
400 type="checkbox"416 type="checkbox"
src/i18n/messages.tsmodified+6 -0
@@ -382,6 +382,8 @@ export type MessageKey =
382 | "exams.retakesHelp"382 | "exams.retakesHelp"
383 | "exams.allowRejoin"383 | "exams.allowRejoin"
384 | "exams.allowRejoinHelp"384 | "exams.allowRejoinHelp"
385+ | "exams.allowReview"
386+ | "exams.allowReviewHelp"
385 | "exams.draft"387 | "exams.draft"
386 | "exams.draftHelp"388 | "exams.draftHelp"
387 | "exams.publish"389 | "exams.publish"
@@ -1205,6 +1207,8 @@ const en: Dict = {
1205 "exams.retakesHelp": "Students can retake the exam this many times before the window closes.",1207 "exams.retakesHelp": "Students can retake the exam this many times before the window closes.",
1206 "exams.allowRejoin": "Allow rejoin",1208 "exams.allowRejoin": "Allow rejoin",
1207 "exams.allowRejoinHelp": "If off, a student who leaves the exam room cannot return to answer.",1209 "exams.allowRejoinHelp": "If off, a student who leaves the exam room cannot return to answer.",
1210+ "exams.allowReview": "Let students review their answers",
1211+ "exams.allowReviewHelp": "Students can see their own paper and past attempts once you've marked this exam.",
1208 "exams.draft": "Draft",1212 "exams.draft": "Draft",
1209 "exams.draftHelp": "Keep hidden from students until published.",1213 "exams.draftHelp": "Keep hidden from students until published.",
1210 "exams.publish": "Publish exam",1214 "exams.publish": "Publish exam",
@@ -2033,6 +2037,8 @@ const tr: Dict = {
2033 "exams.retakesHelp": "Öğrenciler sınav bitmeden bu kadar kez deneme yapabilir.",2037 "exams.retakesHelp": "Öğrenciler sınav bitmeden bu kadar kez deneme yapabilir.",
2034 "exams.allowRejoin": "Yeniden girişe izin ver",2038 "exams.allowRejoin": "Yeniden girişe izin ver",
2035 "exams.allowRejoinHelp": "Kapalıysa sınav odasından çıkan öğrenci cevap vermek için geri giremez.",2039 "exams.allowRejoinHelp": "Kapalıysa sınav odasından çıkan öğrenci cevap vermek için geri giremez.",
2040+ "exams.allowReview": "Öğrenciler cevaplarını inceleyebilsin",
2041+ "exams.allowReviewHelp": "Bu sınavı notlandırdığınızda öğrenciler kendi kağıtlarını ve geçmiş denemelerini görebilir.",
2036 "exams.draft": "Taslak",2042 "exams.draft": "Taslak",
2037 "exams.draftHelp": "Yayınlanana kadar öğrencilerden gizle.",2043 "exams.draftHelp": "Yayınlanana kadar öğrencilerden gizle.",
2038 "exams.publish": "Sınavı yayınla",2044 "exams.publish": "Sınavı yayınla",
src/pages/exam-detail-page.tsxmodified+7 -3
@@ -99,7 +99,6 @@ function ExamDetailContent() {
99 const e = exam();99 const e = exam();
100 return e ? isSittableExam(e) : false;100 return e ? isSittableExam(e) : false;
101 };101 };
102- const isScheduled = () => isSittable();
103 102
104 const [ownResult] = createResource(103 const [ownResult] = createResource(
105 () => (isStudent() ? id() : null),104 () => (isStudent() ? id() : null),
@@ -573,7 +572,7 @@ function ExamDetailContent() {
573 <Tabs value={examTab()} onChange={setExamTab} class="space-y-3">572 <Tabs value={examTab()} onChange={setExamTab} class="space-y-3">
574 <TabsList>573 <TabsList>
575 <TabsTrigger value="schedule">{t("exams.schedule")}</TabsTrigger>574 <TabsTrigger value="schedule">{t("exams.schedule")}</TabsTrigger>
576- <Show when={isStudent() && !isScheduled()}>575+ <Show when={isStudent() && ownResult()}>
577 <TabsTrigger value="ownResult">{t("exams.yourResult")}</TabsTrigger>576 <TabsTrigger value="ownResult">{t("exams.yourResult")}</TabsTrigger>
578 </Show>577 </Show>
579 <Show when={hasCourseManagementRights()}>578 <Show when={hasCourseManagementRights()}>
@@ -605,7 +604,7 @@ function ExamDetailContent() {
605 </div>604 </div>
606 </TabsContent>605 </TabsContent>
607 606
608- <Show when={isStudent() && !isScheduled()}>607+ <Show when={isStudent() && ownResult()}>
609 <TabsContent value="ownResult" forceMount>608 <TabsContent value="ownResult" forceMount>
610 <div class="tab-panel-note mb-4">{ownResult() ? `${t("form.mark")}: ${ownResult()!.mark}` : t("exams.notGraded")}</div>609 <div class="tab-panel-note mb-4">{ownResult() ? `${t("form.mark")}: ${ownResult()!.mark}` : t("exams.notGraded")}</div>
611 <Suspense fallback={<PageSpinner />}>610 <Suspense fallback={<PageSpinner />}>
@@ -613,6 +612,11 @@ function ExamDetailContent() {
613 {(r) => <ExamResultBadge mark={r().mark} />}612 {(r) => <ExamResultBadge mark={r().mark} />}
614 </Show>613 </Show>
615 </Suspense>614 </Suspense>
615+ <Show when={ex().allow_review && ownResult()}>
616+ <div class="mt-6">
617+ <AnswerSheetView examId={id()} userId={auth.user()?.id ?? ""} mode="self" />
618+ </div>
619+ </Show>
616 </TabsContent>620 </TabsContent>
617 </Show>621 </Show>
618 622