feat(school,classes): 学校/年级/班级模块审计修复 — 权限校验 + i18n + 架构图同步

- 新增审计报告 docs/architecture/audit/school-grade-class-audit-report.md

- 修复 P0-4: teacher/classes 4 个页面补充 requirePermission 权限校验

- 修复 P0-5: 新增 school.json i18n 文件(zh-CN/en)并接入 schools-view 组件

- 同步架构图 004:补充 grade-management 死模块记录与 teacher/classes 权限修复说明
This commit is contained in:
SpecialX
2026-06-22 16:44:02 +08:00
parent 22d3f07fcf
commit 10c668f36a
11 changed files with 787 additions and 86 deletions

View File

@@ -1,26 +1,31 @@
import type { Metadata } from "next"
import type { Metadata } from "next"
import type { JSX } from "react"
import { getTranslations } from "next-intl/server"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { SchoolsClient } from "@/modules/school/components/schools-view"
import { getSchools } from "@/modules/school/data-access"
export const metadata: Metadata = {
title: "学校管理 - Next_Edu",
description: "多校区场景下的学校管理",
}
export const dynamic = "force-dynamic"
export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations("school")
return {
title: `${t("schools.title")} - Next_Edu`,
description: t("schools.description"),
}
}
export default async function AdminSchoolsPage(): Promise<JSX.Element> {
await requirePermission(Permissions.SCHOOL_MANAGE)
const t = await getTranslations("school")
const schools = await getSchools()
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-1">
<h2 className="text-2xl font-bold tracking-tight"></h2>
<p className="text-muted-foreground"></p>
<h2 className="text-2xl font-bold tracking-tight">{t("schools.title")}</h2>
<p className="text-muted-foreground">{t("schools.description")}</p>
</div>
<SchoolsClient schools={schools} />
</div>

View File

@@ -1,6 +1,8 @@
import type { JSX } from "react"
import { notFound } from "next/navigation"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getClassHomeworkInsights, getClassSchedule, getClassStudentSubjectScoresV2, getClassStudents } from "@/modules/classes/data-access"
import { ClassAssignmentsWidget } from "@/modules/classes/components/class-detail/class-assignments-widget"
import { ClassTrendsWidget } from "@/modules/classes/components/class-detail/class-trends-widget"
@@ -17,6 +19,7 @@ export default async function ClassDetailPage({
params: Promise<{ id: string }>
}): Promise<JSX.Element> {
const { id } = await params
await requirePermission(Permissions.CLASS_READ)
// Parallel data fetching
const [insights, students, schedule, studentScores] = await Promise.all([

View File

@@ -1,10 +1,13 @@
import type { JSX } from "react"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getClassSubjects, getTeacherClasses } from "@/modules/classes/data-access"
import { MyClassesGrid } from "@/modules/classes/components/my-classes-grid"
export const dynamic = "force-dynamic"
export default async function MyClassesPage(): Promise<JSX.Element> {
await requirePermission(Permissions.CLASS_READ)
const [classes, subjectOptions] = await Promise.all([getTeacherClasses(), getClassSubjects()])
return (

View File

@@ -2,6 +2,8 @@ import type { JSX } from "react"
import { Suspense } from "react"
import { Calendar } from "lucide-react"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getClassSchedule, getTeacherClasses } from "@/modules/classes/data-access"
import { ScheduleFilters } from "@/modules/classes/components/schedule-filters"
import { ScheduleView } from "@/modules/classes/components/schedule-view"
@@ -58,6 +60,7 @@ function ScheduleResultsFallback() {
}
export default async function SchedulePage({ searchParams }: { searchParams: Promise<SearchParams> }): Promise<JSX.Element> {
await requirePermission(Permissions.CLASS_READ)
const classes = await getTeacherClasses()
return (

View File

@@ -2,6 +2,8 @@ import type { JSX } from "react"
import { Suspense } from "react"
import { User } from "lucide-react"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
import { getClassStudents, getTeacherClasses, getStudentsSubjectScores } from "@/modules/classes/data-access"
import { StudentsFilters } from "@/modules/classes/components/students-filters"
import { StudentsTable } from "@/modules/classes/components/students-table"
@@ -76,6 +78,7 @@ function StudentsResultsFallback() {
}
export default async function StudentsPage({ searchParams }: { searchParams: Promise<SearchParams> }): Promise<JSX.Element> {
await requirePermission(Permissions.CLASS_READ)
const classes = await getTeacherClasses()
// Logic to determine default class (first one available)

View File

@@ -37,6 +37,7 @@ export default getRequestConfig(async () => {
diagnostic,
attendance,
elective,
school,
] = await Promise.all([
import(`@/shared/i18n/messages/${locale}/common.json`),
import(`@/shared/i18n/messages/${locale}/auth.json`),
@@ -55,6 +56,7 @@ export default getRequestConfig(async () => {
import(`@/shared/i18n/messages/${locale}/diagnostic.json`),
import(`@/shared/i18n/messages/${locale}/attendance.json`),
import(`@/shared/i18n/messages/${locale}/elective.json`),
import(`@/shared/i18n/messages/${locale}/school.json`),
]);
return {
@@ -77,6 +79,7 @@ export default getRequestConfig(async () => {
diagnostic: diagnostic.default,
attendance: attendance.default,
elective: elective.default,
school: school.default,
},
};
});

View File

@@ -2,8 +2,8 @@
import { useState } from "react"
import { MoreHorizontal, Pencil, Plus, Trash2 } from "lucide-react"
import { toast } from "sonner"
import { useRouter } from "next/navigation"
import { useTranslations } from "next-intl"
import type { SchoolListItem } from "../types"
import { createSchoolAction, deleteSchoolAction, updateSchoolAction } from "../actions"
@@ -33,68 +33,53 @@ import {
AlertDialogTitle,
} from "@/shared/components/ui/alert-dialog"
import { formatDate } from "@/shared/lib/utils"
import { useActionMutation } from "@/shared/hooks/use-action-mutation"
export function SchoolsClient({ schools }: { schools: SchoolListItem[] }) {
const t = useTranslations("school")
const router = useRouter()
const [isWorking, setIsWorking] = useState(false)
const [createOpen, setCreateOpen] = useState(false)
const [editItem, setEditItem] = useState<SchoolListItem | null>(null)
const [deleteItem, setDeleteItem] = useState<SchoolListItem | null>(null)
const handleCreate = async (formData: FormData) => {
setIsWorking(true)
try {
const res = await createSchoolAction(undefined, formData)
if (res.success) {
toast.success(res.message)
setCreateOpen(false)
router.refresh()
} else {
toast.error(res.message || "Failed to create school")
}
} catch {
toast.error("Failed to create school")
} finally {
setIsWorking(false)
}
const createMutation = useActionMutation({
errorMessage: "Failed to create school",
onSuccess: () => {
setCreateOpen(false)
router.refresh()
},
})
const updateMutation = useActionMutation({
errorMessage: "Failed to update school",
onSuccess: () => {
setEditItem(null)
router.refresh()
},
})
const deleteMutation = useActionMutation({
errorMessage: "Failed to delete school",
onSuccess: () => {
setDeleteItem(null)
router.refresh()
},
})
const isWorking = createMutation.isWorking || updateMutation.isWorking || deleteMutation.isWorking
const handleCreate = (formData: FormData) => {
void createMutation.mutate(() => createSchoolAction(undefined, formData))
}
const handleUpdate = async (formData: FormData) => {
const handleUpdate = (formData: FormData) => {
if (!editItem) return
setIsWorking(true)
try {
const res = await updateSchoolAction(editItem.id, undefined, formData)
if (res.success) {
toast.success(res.message)
setEditItem(null)
router.refresh()
} else {
toast.error(res.message || "Failed to update school")
}
} catch {
toast.error("Failed to update school")
} finally {
setIsWorking(false)
}
void updateMutation.mutate(() => updateSchoolAction(editItem.id, undefined, formData))
}
const handleDelete = async () => {
const handleDelete = () => {
if (!deleteItem) return
setIsWorking(true)
try {
const res = await deleteSchoolAction(deleteItem.id)
if (res.success) {
toast.success(res.message)
setDeleteItem(null)
router.refresh()
} else {
toast.error(res.message || "Failed to delete school")
}
} catch {
toast.error("Failed to delete school")
} finally {
setIsWorking(false)
}
void deleteMutation.mutate(() => deleteSchoolAction(deleteItem.id))
}
return (
@@ -102,13 +87,13 @@ export function SchoolsClient({ schools }: { schools: SchoolListItem[] }) {
<div className="flex justify-end">
<Button onClick={() => setCreateOpen(true)} disabled={isWorking}>
<Plus className="mr-2 h-4 w-4" />
New school
{t("schools.new")}
</Button>
</div>
<Card className="shadow-none">
<CardHeader className="flex flex-row items-center justify-between space-y-0">
<CardTitle className="text-base">All schools</CardTitle>
<CardTitle className="text-base">{t("schools.all")}</CardTitle>
<Badge variant="secondary" className="tabular-nums">
{schools.length}
</Badge>
@@ -116,17 +101,17 @@ export function SchoolsClient({ schools }: { schools: SchoolListItem[] }) {
<CardContent>
{schools.length === 0 ? (
<EmptyState
title="No schools"
description="Create your first school to get started."
title={t("schools.empty.title")}
description={t("schools.empty.description")}
className="h-auto border-none shadow-none"
/>
) : (
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Code</TableHead>
<TableHead>Updated</TableHead>
<TableHead>{t("schools.column.name")}</TableHead>
<TableHead>{t("schools.column.code")}</TableHead>
<TableHead>{t("schools.column.updated")}</TableHead>
<TableHead className="w-[60px]" />
</TableRow>
</TableHeader>
@@ -146,7 +131,7 @@ export function SchoolsClient({ schools }: { schools: SchoolListItem[] }) {
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => setEditItem(s)}>
<Pencil className="mr-2 h-4 w-4" />
Edit
{t("schools.actions.edit")}
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
@@ -154,7 +139,7 @@ export function SchoolsClient({ schools }: { schools: SchoolListItem[] }) {
onClick={() => setDeleteItem(s)}
>
<Trash2 className="mr-2 h-4 w-4" />
Delete
{t("schools.actions.delete")}
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
@@ -170,23 +155,23 @@ export function SchoolsClient({ schools }: { schools: SchoolListItem[] }) {
<Dialog open={createOpen} onOpenChange={setCreateOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>New school</DialogTitle>
<DialogTitle>{t("schools.form.createTitle")}</DialogTitle>
</DialogHeader>
<form action={handleCreate} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="name">Name</Label>
<Input id="name" name="name" placeholder="e.g. First Primary School" autoFocus />
<Label htmlFor="name">{t("schools.form.name")}</Label>
<Input id="name" name="name" placeholder={t("schools.form.namePlaceholder")} autoFocus />
</div>
<div className="space-y-2">
<Label htmlFor="code">Code</Label>
<Input id="code" name="code" placeholder="Optional" />
<Label htmlFor="code">{t("schools.form.code")}</Label>
<Input id="code" name="code" placeholder={t("schools.form.codePlaceholder")} />
</div>
<DialogFooter>
<Button type="button" variant="outline" onClick={() => setCreateOpen(false)} disabled={isWorking}>
Cancel
{t("schools.form.cancel")}
</Button>
<Button type="submit" disabled={isWorking}>
Create
{t("schools.form.create")}
</Button>
</DialogFooter>
</form>
@@ -201,24 +186,24 @@ export function SchoolsClient({ schools }: { schools: SchoolListItem[] }) {
>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit school</DialogTitle>
<DialogTitle>{t("schools.form.editTitle")}</DialogTitle>
</DialogHeader>
{editItem ? (
<form action={handleUpdate} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="edit-name">Name</Label>
<Label htmlFor="edit-name">{t("schools.form.name")}</Label>
<Input id="edit-name" name="name" defaultValue={editItem.name} />
</div>
<div className="space-y-2">
<Label htmlFor="edit-code">Code</Label>
<Label htmlFor="edit-code">{t("schools.form.code")}</Label>
<Input id="edit-code" name="code" defaultValue={editItem.code || ""} />
</div>
<DialogFooter>
<Button type="button" variant="outline" onClick={() => setEditItem(null)} disabled={isWorking}>
Cancel
{t("schools.form.cancel")}
</Button>
<Button type="submit" disabled={isWorking}>
Save
{t("schools.form.save")}
</Button>
</DialogFooter>
</form>
@@ -234,15 +219,15 @@ export function SchoolsClient({ schools }: { schools: SchoolListItem[] }) {
>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete school</AlertDialogTitle>
<AlertDialogTitle>{t("schools.delete.title")}</AlertDialogTitle>
<AlertDialogDescription>
This will permanently delete {deleteItem?.name || "this school"} and its grades.
{t("schools.delete.description", { name: deleteItem?.name || "" })}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isWorking}>Cancel</AlertDialogCancel>
<AlertDialogCancel disabled={isWorking}>{t("schools.delete.cancel")}</AlertDialogCancel>
<AlertDialogAction onClick={handleDelete} disabled={isWorking}>
Delete
{t("schools.delete.confirm")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>

View File

@@ -0,0 +1,163 @@
{
"schools": {
"title": "School Management",
"description": "Manage schools across multiple campuses.",
"new": "New school",
"all": "All schools",
"empty": {
"title": "No schools",
"description": "Create your first school to get started."
},
"column": {
"name": "Name",
"code": "Code",
"updated": "Updated",
"actions": "Actions"
},
"form": {
"createTitle": "New school",
"editTitle": "Edit school",
"name": "Name",
"namePlaceholder": "e.g. First Primary School",
"code": "Code",
"codePlaceholder": "Optional",
"cancel": "Cancel",
"create": "Create",
"save": "Save"
},
"delete": {
"title": "Delete school",
"description": "This will permanently delete {name} and its grades.",
"cancel": "Cancel",
"confirm": "Delete"
},
"actions": {
"edit": "Edit",
"delete": "Delete"
}
},
"grades": {
"title": "Grade Management",
"description": "Manage grades and assign grade heads.",
"new": "New grade",
"all": "All grades",
"empty": {
"title": "No grades",
"description": "Create your first grade to get started."
},
"column": {
"school": "School",
"grade": "Grade",
"order": "Order",
"gradeHead": "Grade Head",
"teachingHead": "Teaching Head",
"updated": "Updated",
"actions": "Actions"
},
"form": {
"createTitle": "New grade",
"editTitle": "Edit grade",
"school": "School",
"schoolPlaceholder": "Select school",
"name": "Grade name",
"namePlaceholder": "e.g. Grade 1",
"order": "Order",
"gradeHead": "Grade Head",
"gradeHeadPlaceholder": "Select grade head",
"teachingHead": "Teaching Head",
"teachingHeadPlaceholder": "Select teaching head",
"cancel": "Cancel",
"create": "Create",
"save": "Save"
},
"delete": {
"title": "Delete grade",
"description": "Are you sure you want to delete {name}? This action cannot be undone.",
"cancel": "Cancel",
"confirm": "Delete"
},
"actions": {
"edit": "Edit",
"delete": "Delete"
},
"notSet": "Not set"
},
"departments": {
"title": "Department Management",
"description": "Manage school departments.",
"new": "New department",
"all": "All departments",
"empty": {
"title": "No departments",
"description": "Create your first department to get started."
},
"column": {
"name": "Name",
"description": "Description",
"updated": "Updated",
"actions": "Actions"
},
"form": {
"createTitle": "New department",
"editTitle": "Edit department",
"name": "Name",
"namePlaceholder": "e.g. Chinese Teaching Group",
"description": "Description",
"descriptionPlaceholder": "Optional",
"cancel": "Cancel",
"create": "Create",
"save": "Save"
},
"delete": {
"title": "Delete department",
"description": "Are you sure you want to delete {name}? This action cannot be undone.",
"cancel": "Cancel",
"confirm": "Delete"
},
"actions": {
"edit": "Edit",
"delete": "Delete"
}
},
"academicYear": {
"title": "Academic Year Management",
"description": "Manage academic year periods.",
"new": "New academic year",
"all": "All academic years",
"active": "Active",
"empty": {
"title": "No academic years",
"description": "Create your first academic year to get started."
},
"column": {
"name": "Name",
"startDate": "Start date",
"endDate": "End date",
"status": "Status",
"updated": "Updated",
"actions": "Actions"
},
"form": {
"createTitle": "New academic year",
"editTitle": "Edit academic year",
"name": "Name",
"namePlaceholder": "e.g. 2025-2026",
"startDate": "Start date",
"endDate": "End date",
"isActive": "Set as active year",
"cancel": "Cancel",
"create": "Create",
"save": "Save"
},
"delete": {
"title": "Delete academic year",
"description": "Are you sure you want to delete {name}? This action cannot be undone.",
"cancel": "Cancel",
"confirm": "Delete"
},
"actions": {
"edit": "Edit",
"delete": "Delete"
}
}
}

View File

@@ -0,0 +1,163 @@
{
"schools": {
"title": "学校管理",
"description": "多校区场景下的学校管理。",
"new": "新建学校",
"all": "所有学校",
"empty": {
"title": "暂无学校",
"description": "创建你的第一所学校以开始使用。"
},
"column": {
"name": "名称",
"code": "代码",
"updated": "更新时间",
"actions": "操作"
},
"form": {
"createTitle": "新建学校",
"editTitle": "编辑学校",
"name": "名称",
"namePlaceholder": "如:第一小学",
"code": "代码",
"codePlaceholder": "可选",
"cancel": "取消",
"create": "创建",
"save": "保存"
},
"delete": {
"title": "删除学校",
"description": "此操作将永久删除「{name}」及其下属年级,不可撤销。",
"cancel": "取消",
"confirm": "删除"
},
"actions": {
"edit": "编辑",
"delete": "删除"
}
},
"grades": {
"title": "年级管理",
"description": "管理年级并分配年级组长。",
"new": "新建年级",
"all": "所有年级",
"empty": {
"title": "暂无年级",
"description": "创建你的第一个年级以开始使用。"
},
"column": {
"school": "学校",
"grade": "年级",
"order": "排序",
"gradeHead": "年级主任",
"teachingHead": "教学主任",
"updated": "更新时间",
"actions": "操作"
},
"form": {
"createTitle": "新建年级",
"editTitle": "编辑年级",
"school": "学校",
"schoolPlaceholder": "选择学校",
"name": "年级名称",
"namePlaceholder": "如:一年级",
"order": "排序",
"gradeHead": "年级主任",
"gradeHeadPlaceholder": "选择年级主任",
"teachingHead": "教学主任",
"teachingHeadPlaceholder": "选择教学主任",
"cancel": "取消",
"create": "创建",
"save": "保存"
},
"delete": {
"title": "删除年级",
"description": "确定要删除「{name}」吗?此操作不可撤销。",
"cancel": "取消",
"confirm": "删除"
},
"actions": {
"edit": "编辑",
"delete": "删除"
},
"notSet": "未设置"
},
"departments": {
"title": "部门管理",
"description": "管理学校部门。",
"new": "新建部门",
"all": "所有部门",
"empty": {
"title": "暂无部门",
"description": "创建你的第一个部门以开始使用。"
},
"column": {
"name": "名称",
"description": "描述",
"updated": "更新时间",
"actions": "操作"
},
"form": {
"createTitle": "新建部门",
"editTitle": "编辑部门",
"name": "名称",
"namePlaceholder": "如:语文教研组",
"description": "描述",
"descriptionPlaceholder": "可选",
"cancel": "取消",
"create": "创建",
"save": "保存"
},
"delete": {
"title": "删除部门",
"description": "确定要删除「{name}」吗?此操作不可撤销。",
"cancel": "取消",
"confirm": "删除"
},
"actions": {
"edit": "编辑",
"delete": "删除"
}
},
"academicYear": {
"title": "学年管理",
"description": "管理学年起止时间。",
"new": "新建学年",
"all": "所有学年",
"active": "当前学年",
"empty": {
"title": "暂无学年",
"description": "创建你的第一个学年开始使用。"
},
"column": {
"name": "名称",
"startDate": "开始日期",
"endDate": "结束日期",
"status": "状态",
"updated": "更新时间",
"actions": "操作"
},
"form": {
"createTitle": "新建学年",
"editTitle": "编辑学年",
"name": "名称",
"namePlaceholder": "如2025-2026学年",
"startDate": "开始日期",
"endDate": "结束日期",
"isActive": "设为当前学年",
"cancel": "取消",
"create": "创建",
"save": "保存"
},
"delete": {
"title": "删除学年",
"description": "确定要删除「{name}」吗?此操作不可撤销。",
"cancel": "取消",
"confirm": "删除"
},
"actions": {
"edit": "编辑",
"delete": "删除"
}
}
}