Step 12:后端轻量优化(API 稳定性 & 前端友好)
This commit is contained in:
@@ -5,6 +5,7 @@ from fastapi import Depends, HTTPException, status
|
||||
from pydantic import ValidationError
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.exceptions import AppException
|
||||
from app.core.security import decode_token, oauth2_scheme
|
||||
from app.crud import user as user_crud
|
||||
from app.crud import member as member_crud
|
||||
@@ -75,9 +76,10 @@ def require_study_member():
|
||||
return current_user
|
||||
membership = await member_crud.get_member(db, study_id, current_user.id)
|
||||
if not membership or not membership.is_active:
|
||||
raise HTTPException(
|
||||
raise AppException(
|
||||
code="FORBIDDEN",
|
||||
message="Not a member of this study",
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Not a member of this study",
|
||||
)
|
||||
return current_user
|
||||
|
||||
@@ -96,9 +98,10 @@ def require_study_roles(roles: Iterable[str]):
|
||||
return current_user
|
||||
membership = await member_crud.get_member(db, study_id, current_user.id)
|
||||
if not membership or not membership.is_active or membership.role_in_study not in roles_set:
|
||||
raise HTTPException(
|
||||
raise AppException(
|
||||
code="FORBIDDEN",
|
||||
message="Insufficient study permissions",
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Insufficient study permissions",
|
||||
)
|
||||
return current_user
|
||||
|
||||
|
||||
Reference in New Issue
Block a user