跨域bug修复2
This commit is contained in:
@@ -16,6 +16,7 @@ from functools import wraps
|
||||
from utils.response import forbidden_response
|
||||
from utils.database import execute_one
|
||||
from utils.logger import get_logger
|
||||
from models.admin_role import AdminRoleModel
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -91,6 +92,25 @@ class PermissionChecker:
|
||||
# 本系统为单班级设计,class_id 固定为 1
|
||||
return 1
|
||||
|
||||
@staticmethod
|
||||
async def get_user_subject_ids(user_id: int) -> List[int]:
|
||||
"""获取用户管理的科目ID列表"""
|
||||
admin_role = await AdminRoleModel.get_by_user_id(user_id)
|
||||
if admin_role and admin_role.get("subject_id"):
|
||||
return [admin_role["subject_id"]]
|
||||
# 班主任可以管理所有科目
|
||||
if admin_role and admin_role["role_type"] == "班主任":
|
||||
from models.subject import SubjectModel
|
||||
subjects = await SubjectModel.get_all(is_active=True)
|
||||
return [s["subject_id"] for s in subjects]
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
async def check_can_manage_student(user_id: int, student_id: int) -> bool:
|
||||
"""检查是否可以管理指定学生(管理员默认可管理所有学生)"""
|
||||
role = await PermissionChecker.get_user_role(user_id)
|
||||
return role is not None
|
||||
|
||||
@staticmethod
|
||||
async def check_can_revoke(user_id: int, record_id: int) -> bool:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user