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
+5
View File
@@ -3,9 +3,14 @@
"""
from fastapi import APIRouter
from api.routers import auth
from api.routers import customer_agent
from api.routers import knowledge
from api.routers import auth, product, questionnaire
api_router = APIRouter()
api_router.include_router(auth.router, prefix="/api", tags=["认证"])
api_router.include_router(customer_agent.router, prefix="/api/agent/customer", tags=["客服Agent"])
api_router.include_router(knowledge.router, prefix="/api/knowledge", tags=["知识库"])
api_router.include_router(product.router, prefix="/api", tags=["产品"])
api_router.include_router(questionnaire.router, prefix="/api", tags=["问卷"])