fix: 更新main.py逻辑

This commit is contained in:
2026-09-11 10:47:01 +08:00
parent d2a3f024c4
commit 5915319f9f
9 changed files with 66 additions and 8 deletions
+13 -1
View File
@@ -9,6 +9,9 @@ from service.auth import decode_token
from utils.exceptions import AuthError, ForbiddenError
KNOWLEDGE_OPERATOR_ROLES = {"ADMIN", "KNOWLEDGE_ADMIN", "KNOWLEDGE_OPERATOR", "运营"}
async def get_current_user(
request: Request, db: AsyncSession = Depends(get_db)
) -> SysUser:
@@ -24,4 +27,13 @@ async def get_current_user(
raise AuthError("用户不存在")
if user.status != "正常":
raise ForbiddenError("账号已被禁用或冻结")
return user
return user
async def require_knowledge_operator(user: SysUser = Depends(get_current_user)) -> SysUser:
"""Allow only administrators or explicitly assigned knowledge operators."""
if user.user_type == "ADMIN":
return user
if user.user_type != "EMPLOYEE" or user.employee_role not in KNOWLEDGE_OPERATOR_ROLES:
raise ForbiddenError("仅运营人员可以管理知识库")
return user