feat(exam-homework): add audit report, i18n, error boundaries, and permission hardening
- Add comprehensive audit report for exam and homework module - Create exam-homework i18n message files (zh-CN + en) and register namespace - Add permission check to gradeHomeworkSubmissionAction to prevent horizontal privilege escalation - Add Error Boundary + loading.tsx for 5 key pages (exam build/proctoring, homework assignment/submissions, student assignment) - Refactor exam-columns to createExamColumns(t) factory for i18n support - Refactor exam-data-table to manage columns internally via useTranslations - Replace hardcoded strings with i18n keys in all exam/homework components and pages - Add getHomeworkSubmissionForGrading data-access for secure grading flow
This commit is contained in:
24
src/app/(dashboard)/teacher/exams/[id]/build/error.tsx
Normal file
24
src/app/(dashboard)/teacher/exams/[id]/build/error.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function BuildExamError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
const t = useTranslations("examHomework")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title={t("exam.error.loadFailed")}
|
||||
description={t("exam.error.notFound")}
|
||||
action={{
|
||||
label: t("common.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
16
src/app/(dashboard)/teacher/exams/[id]/build/loading.tsx
Normal file
16
src/app/(dashboard)/teacher/exams/[id]/build/loading.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-4 p-4">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-7 w-40" />
|
||||
<Skeleton className="h-4 w-72" />
|
||||
</div>
|
||||
<div className="grid w-full grid-cols-1 gap-4 lg:grid-cols-3">
|
||||
<Skeleton className="h-[600px] lg:col-span-2" />
|
||||
<Skeleton className="h-[600px] lg:col-span-1" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
24
src/app/(dashboard)/teacher/exams/[id]/proctoring/error.tsx
Normal file
24
src/app/(dashboard)/teacher/exams/[id]/proctoring/error.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import { AlertCircle } from "lucide-react"
|
||||
import { useTranslations } from "next-intl"
|
||||
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
|
||||
export default function ProctoringError({ reset }: { error: Error & { digest?: string }; reset: () => void }) {
|
||||
const t = useTranslations("examHomework")
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
|
||||
<EmptyState
|
||||
icon={AlertCircle}
|
||||
title={t("exam.error.loadFailed")}
|
||||
description={t("exam.error.notFound")}
|
||||
action={{
|
||||
label: t("common.retry"),
|
||||
onClick: () => reset(),
|
||||
}}
|
||||
className="border-none shadow-none h-auto"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-4 p-4">
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-7 w-48" />
|
||||
<Skeleton className="h-4 w-72" />
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-3">
|
||||
<Skeleton className="h-32" />
|
||||
<Skeleton className="h-32" />
|
||||
<Skeleton className="h-32" />
|
||||
</div>
|
||||
<Skeleton className="h-[500px] w-full" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { JSX } from "react"
|
||||
import { Suspense } from "react"
|
||||
import Link from "next/link"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
import { Button } from "@/shared/components/ui/button"
|
||||
import { Badge } from "@/shared/components/ui/badge"
|
||||
import { EmptyState } from "@/shared/components/ui/empty-state"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
import { ExamDataTable } from "@/modules/exams/components/exam-data-table"
|
||||
import { examColumns } from "@/modules/exams/components/exam-columns"
|
||||
import { ExamFilters } from "@/modules/exams/components/exam-filters"
|
||||
import { getExams } from "@/modules/exams/data-access"
|
||||
import { getAuthContext } from "@/shared/lib/auth-guard"
|
||||
@@ -16,6 +16,7 @@ import { FileText, PlusCircle } from "lucide-react"
|
||||
async function ExamsResults({ searchParams }: { searchParams: Promise<SearchParams> }): Promise<JSX.Element> {
|
||||
const params = await searchParams
|
||||
const { dataScope } = await getAuthContext()
|
||||
const t = await getTranslations("examHomework")
|
||||
|
||||
const q = getParam(params, "q")
|
||||
const status = getParam(params, "status")
|
||||
@@ -45,20 +46,20 @@ async function ExamsResults({ searchParams }: { searchParams: Promise<SearchPara
|
||||
<div className="space-y-4">
|
||||
<div className="flex flex-col gap-3 rounded-md border bg-card px-4 py-3 md:flex-row md:items-center md:justify-between">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-sm text-muted-foreground">Showing</span>
|
||||
<span className="text-sm text-muted-foreground">{t("exam.list.showing")}</span>
|
||||
<span className="text-sm font-medium">{counts.total}</span>
|
||||
<span className="text-sm text-muted-foreground">exams</span>
|
||||
<span className="text-sm text-muted-foreground">{t("exam.list.examsUnit")}</span>
|
||||
<Badge variant="outline" className="ml-0 md:ml-2">
|
||||
Draft {counts.draft}
|
||||
{t("exam.status.draft")} {counts.draft}
|
||||
</Badge>
|
||||
<Badge variant="outline">Published {counts.published}</Badge>
|
||||
<Badge variant="outline">Archived {counts.archived}</Badge>
|
||||
<Badge variant="outline">{t("exam.status.published")} {counts.published}</Badge>
|
||||
<Badge variant="outline">{t("exam.status.archived")} {counts.archived}</Badge>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button asChild size="sm">
|
||||
<Link href="/teacher/exams/create" className="inline-flex items-center gap-2">
|
||||
<PlusCircle className="h-4 w-4" aria-hidden="true" />
|
||||
Create Exam
|
||||
{t("exam.list.create")}
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
@@ -67,27 +68,27 @@ async function ExamsResults({ searchParams }: { searchParams: Promise<SearchPara
|
||||
{exams.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={FileText}
|
||||
title={hasFilters ? "No exams match your filters" : "No exams yet"}
|
||||
title={hasFilters ? t("exam.list.emptyFiltered") : t("exam.list.empty")}
|
||||
description={
|
||||
hasFilters
|
||||
? "Try clearing filters or adjusting keywords."
|
||||
: "Create your first exam to start assigning and grading."
|
||||
? t("exam.list.emptyFilteredDescription")
|
||||
: t("exam.list.emptyDescription")
|
||||
}
|
||||
action={
|
||||
hasFilters
|
||||
? {
|
||||
label: "Clear filters",
|
||||
label: t("exam.list.clearFilters"),
|
||||
href: "/teacher/exams/all",
|
||||
}
|
||||
: {
|
||||
label: "Create Exam",
|
||||
label: t("exam.list.create"),
|
||||
href: "/teacher/exams/create",
|
||||
}
|
||||
}
|
||||
className="h-[360px] bg-card"
|
||||
/>
|
||||
) : (
|
||||
<ExamDataTable columns={examColumns} data={exams} />
|
||||
<ExamDataTable data={exams} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user