refactor: fix remaining P2 architecture issues

Fix P2-6: proxy.ts now uses Permissions constants instead of hardcoded strings

Fix P2-7: useA11yId file no longer exists (use-aria-live.ts already in hooks/)

Fix P2-8: schema.ts section numbering reordered to continuous 1-24

Fix P2-11: announcements dead code void wasPublished already removed

Fix P2-17: app-sidebar.tsx uses hasRole() instead of permission-based role inference

Fix P2-18: scheduling/actions.ts removes trailing re-export of data-access; 4 pages now import directly from data-access

Sync architecture docs 004 and 005
This commit is contained in:
SpecialX
2026-06-20 01:00:06 +08:00
parent 49291fcc31
commit d8962aba96
10 changed files with 94 additions and 52 deletions

View File

@@ -3,7 +3,7 @@ import { CalendarClock, ClipboardList, Settings2 } from "lucide-react"
import { Button } from "@/shared/components/ui/button"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { getAdminClassesForScheduling } from "@/modules/scheduling/actions"
import { getAdminClassesForScheduling } from "@/modules/scheduling/data-access"
import { AutoSchedulePanel } from "@/modules/scheduling/components/auto-schedule-panel"
export const dynamic = "force-dynamic"

View File

@@ -6,7 +6,7 @@ import { EmptyState } from "@/shared/components/ui/empty-state"
import {
getAdminClassesForScheduling,
getScheduleChanges,
} from "@/modules/scheduling/actions"
} from "@/modules/scheduling/data-access"
import { ScheduleChangeList } from "@/modules/scheduling/components/schedule-change-list"
import { ScheduleConflictsView } from "@/modules/scheduling/components/schedule-conflicts-view"
import type { ScheduleChangeStatus } from "@/modules/scheduling/types"

View File

@@ -4,7 +4,7 @@ import { EmptyState } from "@/shared/components/ui/empty-state"
import {
getAdminClassesForScheduling,
getSchedulingRules,
} from "@/modules/scheduling/actions"
} from "@/modules/scheduling/data-access"
import { SchedulingRulesForm } from "@/modules/scheduling/components/scheduling-rules-form"
export const dynamic = "force-dynamic"

View File

@@ -6,7 +6,7 @@ import {
getAdminClassesForScheduling,
getScheduleChanges,
getTeachersForScheduling,
} from "@/modules/scheduling/actions"
} from "@/modules/scheduling/data-access"
import { ScheduleChangeForm } from "@/modules/scheduling/components/schedule-change-form"
import { ScheduleChangeList } from "@/modules/scheduling/components/schedule-change-list"

View File

@@ -19,7 +19,7 @@ import {
} from "@/shared/components/ui/tooltip"
import { cn } from "@/shared/lib/utils"
import { usePermission } from "@/shared/hooks"
import { Permissions, type Permission } from "@/shared/types/permissions"
import { type Permission } from "@/shared/types/permissions"
import { useSidebar } from "./sidebar-provider"
import { NAV_CONFIG, Role } from "../config/navigation"
@@ -32,11 +32,11 @@ export function AppSidebar({ mode }: AppSidebarProps) {
const pathname = usePathname()
const { permissions, hasRole } = usePermission()
// Determine which role's nav config to use based on permissions
// Determine which role's nav config to use based on session roles
let currentRole: Role = "teacher"
if (permissions.includes(Permissions.SCHOOL_MANAGE)) {
if (hasRole("admin")) {
currentRole = "admin"
} else if (permissions.includes(Permissions.HOMEWORK_SUBMIT) && !permissions.includes(Permissions.EXAM_CREATE)) {
} else if (hasRole("student")) {
currentRole = "student"
} else if (hasRole("parent")) {
currentRole = "parent"

View File

@@ -15,8 +15,6 @@ import {
createScheduleChange,
updateScheduleChangeStatus,
getClassConflicts,
getAdminClassesForScheduling,
getTeachersForScheduling,
getClassroomsForScheduling,
getClassSubjectsForScheduling,
replaceClassSchedule,
@@ -280,13 +278,3 @@ export async function getClassConflictsAction(
return { success: false, message: "Unexpected error" }
}
}
// Re-export data-access for server pages
export {
getSchedulingRules,
getScheduleChanges,
getClassConflicts,
getAdminClassesForScheduling,
getTeachersForScheduling,
getClassroomsForScheduling,
}

View File

@@ -2,20 +2,22 @@ import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
import { getToken } from "next-auth/jwt"
import { Permissions } from "@/shared/types/permissions"
// Route prefix → minimum required permission
// Note: /admin/announcements is covered by /admin prefix (requires school:manage)
// Note: /announcements is accessible to all authenticated users (no permission entry needed)
const ROUTE_PERMISSIONS: Record<string, string> = {
"/admin": "school:manage",
"/teacher": "exam:read",
"/student": "homework:submit",
"/parent": "exam:read",
"/management": "grade:manage",
"/admin": Permissions.SCHOOL_MANAGE,
"/teacher": Permissions.EXAM_READ,
"/student": Permissions.HOMEWORK_SUBMIT,
"/parent": Permissions.EXAM_READ,
"/management": Permissions.GRADE_MANAGE,
}
// API route prefix → required permission
const API_PERMISSIONS: Record<string, string> = {
"/api/ai/chat": "ai:chat",
"/api/ai/chat": Permissions.AI_CHAT,
}
function resolveDefaultPath(roles: string[]): string {

View File

@@ -418,7 +418,7 @@ export const classSchedule = mysqlTable("class_schedule", {
}).onDelete("cascade"),
}));
// --- P2: Exam Proctoring (考试监考) ---
// --- 7. Exam Proctoring Config (考试监考配置) ---
export const examModeEnum = mysqlEnum("exam_mode", ["homework", "timed", "proctored"]);
export const proctoringEventTypeEnum = mysqlEnum("event_type", [
@@ -650,7 +650,7 @@ export const aiProviders = mysqlTable("ai_providers", {
defaultIdx: index("ai_provider_default_idx").on(table.isDefault),
}));
// --- 7. Announcements ---
// --- 8. Announcements ---
export const announcementTypeEnum = mysqlEnum("type", ["school", "grade", "class"]);
export const announcementStatusEnum = mysqlEnum("status", ["draft", "published", "archived"]);
@@ -675,7 +675,7 @@ export const announcements = mysqlTable("announcements", {
targetClassIdx: index("announcements_target_class_idx").on(table.targetClassId),
}));
// --- 8. Audit & Login Logs ---
// --- 9. Audit & Login Logs ---
export const auditLogStatusEnum = mysqlEnum("status", ["success", "failure"]);
@@ -721,7 +721,7 @@ export const loginLogs = mysqlTable("login_logs", {
createdAtIdx: index("login_logs_created_at_idx").on(table.createdAt),
}));
// --- 8b. Data Change Logs (数据变更日志) ---
// --- 10. Data Change Logs (数据变更日志) ---
export const dataChangeLogActionEnum = mysqlEnum("action", ["create", "update", "delete"]);
@@ -749,7 +749,7 @@ export const dataChangeLogs = mysqlTable("data_change_logs", {
// But if there were existing tables, we might keep them or comment them out.
// For this task, I will overwrite completely as this is a "System Architect" redesign.
// --- 9. Grade Records (成绩录入) ---
// --- 11. Grade Records (成绩录入) ---
export const gradeRecordTypeEnum = mysqlEnum("type", ["exam", "quiz", "homework", "other"]);
export const gradeRecordSemesterEnum = mysqlEnum("semester", ["1", "2"]);
@@ -799,7 +799,7 @@ export const gradeRecords = mysqlTable("grade_records", {
}).onDelete("cascade"),
}));
// --- 10. File Attachments (文件附件) ---
// --- 12. File Attachments (文件附件) ---
export const fileAttachments = mysqlTable("file_attachments", {
id: varchar("id", { length: 128 }).primaryKey(),
@@ -819,7 +819,7 @@ export const fileAttachments = mysqlTable("file_attachments", {
createdAtIdx: index("file_attachments_created_at_idx").on(table.createdAt),
}));
// --- 11. Course Plans (课程计划) ---
// --- 13. Course Plans (课程计划) ---
export const coursePlanStatusEnum = mysqlEnum("status", ["planning", "active", "completed", "paused"]);
export const coursePlanSemesterEnum = mysqlEnum("semester", ["1", "2"]);
@@ -893,7 +893,7 @@ export const coursePlanItems = mysqlTable("course_plan_items", {
}).onDelete("cascade"),
}));
// --- 13. Messages (站内消息) ---
// --- 14. Messages (站内消息) ---
export const messages = mysqlTable("messages", {
id: id("id").primaryKey(),
@@ -913,7 +913,7 @@ export const messages = mysqlTable("messages", {
receiverReadIdx: index("messages_receiver_read_idx").on(table.receiverId, table.isRead),
}));
// --- 14. Message Notifications (消息通知) ---
// --- 15. Message Notifications (消息通知) ---
export const messageNotifications = mysqlTable("message_notifications", {
id: id("id").primaryKey(),
@@ -931,7 +931,7 @@ export const messageNotifications = mysqlTable("message_notifications", {
createdAtIdx: index("message_notifications_created_at_idx").on(table.createdAt),
}));
// --- 14b. Notification Preferences (通知偏好) ---
// --- 16. Notification Preferences (通知偏好) ---
export const notificationPreferences = mysqlTable("notification_preferences", {
id: varchar("id", { length: 128 }).primaryKey(),
@@ -955,7 +955,7 @@ export const notificationPreferences = mysqlTable("notification_preferences", {
}).onDelete("cascade"),
}));
// --- 12. Parent-Student Relations (家长-子女关联) ---
// --- 17. Parent-Student Relations (家长-子女关联) ---
export const parentStudentRelations = mysqlTable("parent_student_relations", {
id: varchar("id", { length: 128 }).primaryKey().$defaultFn(() => createId()),
@@ -978,7 +978,7 @@ export const parentStudentRelations = mysqlTable("parent_student_relations", {
}).onDelete("cascade"),
}));
// --- 15. Attendance (考勤管理) ---
// --- 18. Attendance (考勤管理) ---
export const attendanceStatusEnum = mysqlEnum("status", ["present", "absent", "late", "early_leave", "excused"]);
@@ -1035,7 +1035,7 @@ export const attendanceRules = mysqlTable("attendance_rules", {
}).onDelete("cascade"),
}));
// --- 17. Password Security (密码安全策略) ---
// --- 19. Password Security (密码安全策略) ---
export const passwordSecurity = mysqlTable("password_security", {
id: varchar("id", { length: 128 }).primaryKey().$defaultFn(() => createId()),
@@ -1056,7 +1056,7 @@ export const passwordSecurity = mysqlTable("password_security", {
}).onDelete("cascade"),
}));
// --- 16. Scheduling Rules & Schedule Changes (排课规则与调课) ---
// --- 20. Scheduling Rules & Schedule Changes (排课规则与调课) ---
export const schedulingRules = mysqlTable("scheduling_rules", {
id: id("id").primaryKey(),
@@ -1100,7 +1100,7 @@ export const scheduleChanges = mysqlTable("schedule_changes", {
originalScheduleIdx: index("schedule_changes_original_schedule_idx").on(table.originalScheduleId),
}));
// --- P2: Elective Course Management (选课管理) ---
// --- 21. Elective Course Management (选课管理) ---
export const electiveCourseStatusEnum = mysqlEnum("status", ["draft", "open", "closed", "cancelled"]);
export const electiveSelectionModeEnum = mysqlEnum("selection_mode", ["fcfs", "lottery"]);
@@ -1152,7 +1152,7 @@ export const courseSelections = mysqlTable("course_selections", {
statusIdx: index("course_selections_status_idx").on(table.status),
}));
// --- P2: Exam Proctoring (考试监考) ---
// --- 22. Exam Proctoring Events (考试监考事件) ---
export const examProctoringEvents = mysqlTable("exam_proctoring_events", {
id: id("id").primaryKey(),
@@ -1170,7 +1170,7 @@ export const examProctoringEvents = mysqlTable("exam_proctoring_events", {
eventTypeIdx: index("proctoring_event_type_idx").on(table.eventType),
}));
// --- P2: Learning Diagnostic (学情诊断报告) ---
// --- 23. Learning Diagnostic (学情诊断报告) ---
export const knowledgePointMastery = mysqlTable("knowledge_point_mastery", {
id: id("id").primaryKey(),
@@ -1211,3 +1211,55 @@ export const learningDiagnosticReports = mysqlTable("learning_diagnostic_reports
statusIdx: index("diagnostic_status_idx").on(table.status),
reportTypeIdx: index("diagnostic_report_type_idx").on(table.reportType),
}));
// --- 24. Lesson Preparation (备课) ---
export const lessonPlans = mysqlTable("lesson_plans", {
id: id("id").primaryKey(),
title: varchar("title", { length: 255 }).notNull(),
textbookId: varchar("textbook_id", { length: 128 }).references(() => textbooks.id),
chapterId: varchar("chapter_id", { length: 128 }).references(() => chapters.id),
coursePlanItemId: varchar("course_plan_item_id", { length: 128 }),
subjectId: varchar("subject_id", { length: 128 }).references(() => subjects.id),
gradeId: varchar("grade_id", { length: 128 }).references(() => grades.id),
templateId: varchar("template_id", { length: 128 }),
templateName: varchar("template_name", { length: 100 }),
content: json("content").notNull(),
status: varchar("status", { length: 50 }).default("draft").notNull(),
creatorId: varchar("creator_id", { length: 128 }).notNull().references(() => users.id),
lastSavedAt: timestamp("last_saved_at"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
}, (table) => ({
creatorIdx: index("lp_creator_idx").on(table.creatorId),
statusIdx: index("lp_status_idx").on(table.status),
textbookChapterIdx: index("lp_textbook_chapter_idx").on(table.textbookId, table.chapterId),
subjectGradeIdx: index("lp_subject_grade_idx").on(table.subjectId, table.gradeId),
}));
export const lessonPlanVersions = mysqlTable("lesson_plan_versions", {
id: id("id").primaryKey(),
planId: varchar("plan_id", { length: 128 }).notNull().references(() => lessonPlans.id, { onDelete: "cascade" }),
versionNo: int("version_no").notNull(),
label: varchar("label", { length: 100 }),
content: json("content").notNull(),
isAuto: boolean("is_auto").default(false).notNull(),
creatorId: varchar("creator_id", { length: 128 }).notNull().references(() => users.id),
createdAt: timestamp("created_at").defaultNow().notNull(),
}, (table) => ({
planVersionIdx: index("lpv_plan_version_idx").on(table.planId, table.versionNo),
planCreatedIdx: index("lpv_plan_created_idx").on(table.planId, table.createdAt),
}));
export const lessonPlanTemplates = mysqlTable("lesson_plan_templates", {
id: id("id").primaryKey(),
name: varchar("name", { length: 100 }).notNull(),
type: varchar("type", { length: 50 }).notNull(),
scope: varchar("scope", { length: 50 }).notNull(),
blocks: json("blocks").notNull(),
creatorId: varchar("creator_id", { length: 128 }).references(() => users.id),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow().notNull(),
}, (table) => ({
typeCreatorIdx: index("lpt_type_creator_idx").on(table.type, table.creatorId),
}));