Files
ClassHelper/packages/shared/src/lifecycle.ts
T
LoveChengke 66be3a63b1 feat(authz): 重写权限模板分配与班级授权边界
拆分能力、分配范围和业务关系,固定管理员能力并收紧组织级写入口。
补齐内容、课表、设备会话和实时通道授权,兼容旧库分配及历史快照。
重写权限分配预览,按实际可操作范围展示维护入口,合并学生入口并独立学年升级页。
增加授权攻击矩阵及静态门禁,更新隔离回归与开发契约。

验证:授权矩阵 23 段通过,Node 24 下 Web 63/63,类型检查、lint 与文档严格构建通过。
2026-10-31 09:40:23 +08:00

59 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { PermissionScope } from './class-plan.js';
/** 范围解析供保存、查询与展示共用;旧库空岗位范围会由调用方拒绝访问。 */
export function parsePermissionScope(scope: PermissionScope, value = '', knownGrades?: readonly string[]) {
if (scope === 'ALL' || scope === 'TEACHING' || scope === 'HEAD') {
if (value !== '') throw new Error('关联班级或全校范围不接受范围值');
return {
scope,
scopeValue: '',
grades: [],
scopeLabel: scope === 'ALL' ? '全校' : scope === 'HEAD' ? '仅班主任班' : '班主任与任课班级',
};
}
if (scope !== 'GRADE' && scope !== 'DIVISION') throw new Error('未知的数据范围');
const grades = [...new Set(value.split(/[,,、\s]+/u).filter(Boolean))].sort();
if (!grades.length) throw new Error('请选择范围中的年级');
if (scope === 'GRADE' && grades.length !== 1) throw new Error('年级范围只能选择一个年级');
if (knownGrades && grades.some((grade) => !knownGrades.includes(grade)))
throw new Error('范围包含未知年级,请刷新选项');
return {
scope,
scopeValue: grades.join(','),
grades,
scopeLabel: `${scope === 'GRADE' ? '年级' : '部'}:${grades.join('、')}`,
};
}
export interface PromotionPlan {
tracks: {
id: string;
name: string;
entryClassCount: number;
stages: { grade: string; terminal?: boolean }[];
}[];
termStartDate: string | null;
resetTermWeeks: boolean;
}
export function defaultPromotionPlan(classCount = 1): PromotionPlan {
return {
tracks: [
{
id: 'high',
name: '高中',
entryClassCount: classCount,
stages: [{ grade: '高一' }, { grade: '高二' }, { grade: '高三', terminal: true }],
},
],
termStartDate: null,
resetTermWeeks: true,
};
}
/** 仅迁移和旧快照恢复使用;运行时不接受旧枚举。 */
export function migratePermissionScope(scope: string, scopeValue = '') {
return scope === 'SELF_CLASS'
? { scope: scopeValue === 'HEAD' ? 'HEAD' : 'TEACHING', scopeValue: '' }
: { scope, scopeValue };
}