fix(authz): 禁止教师通过新建课程自授任课关系
This commit is contained in:
1 parent
71cc8eb605
commit
e49dd0bc39
8 files changed
+36
-14
No files matched your search
@@ -697,11 +697,17 @@ async function main() {
|
||||
|
||||
const createdCourse = await api('/courses', {
|
||||
method: 'POST',
|
||||
token: teacherToken,
|
||||
token: adminToken,
|
||||
body: { name: `联调验证课程 ${Date.now()}`, classId },
|
||||
});
|
||||
const createdCourseId = createdCourse.payload?.data?.id;
|
||||
record('新增课程 POST /courses', createdCourse.status === 201, `status=${createdCourse.status}`);
|
||||
const deniedCourse = await api('/courses', {
|
||||
method: 'POST',
|
||||
token: teacherToken,
|
||||
body: { name: `禁止自授权课程 ${Date.now()}`, classId },
|
||||
});
|
||||
record('教师不能通过建课建立任课关系', deniedCourse.status === 403, `status=${deniedCourse.status}`);
|
||||
if (createdCourseId) {
|
||||
const removedCourse = await api(`/courses/${createdCourseId}`, { method: 'DELETE', token: teacherToken });
|
||||
record('删除课程 DELETE /courses/:id', removedCourse.status === 200, `status=${removedCourse.status}`);
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { refreshClassSubscriptions } from '../../realtime/bus.js';
|
||||
import type { CourseDto } from '@classhelper/shared';
|
||||
import { assertCanManageSchedule, classScopeWhere, resolveClassScope } from '../../lib/access.js';
|
||||
import {
|
||||
assertCanAssignTeachers,
|
||||
assertCanManageSchedule,
|
||||
classScopeWhere,
|
||||
resolveClassScope,
|
||||
} from '../../lib/access.js';
|
||||
import { prisma } from '../../lib/db.js';
|
||||
import { ApiError } from '../../lib/http.js';
|
||||
import type { TokenPayload } from '../../lib/jwt.js';
|
||||
@@ -21,6 +26,9 @@ export async function listCourses(user: TokenPayload, classId?: string): Promise
|
||||
|
||||
export async function createCourse(user: TokenPayload, input: CreateCourseInput): Promise<CourseDto> {
|
||||
await assertCanManageSchedule(user, input.classId);
|
||||
// 建课同时建立任课关系,只能由管理员执行,不能凭课表维护范围自授权。
|
||||
if (user.role !== 'ADMIN') throw ApiError.forbidden('新建科目会建立任课关系,请联系管理员配置');
|
||||
await assertCanAssignTeachers(user, input.classId);
|
||||
|
||||
/*
|
||||
* 同名去重(一个班级里科目名唯一)。
|
||||
|
||||
Reference in new issue
Block a user