11
This commit is contained in:
@@ -4,7 +4,7 @@ import redis.asyncio as redis
|
||||
from fastapi import Depends, Header, HTTPException, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.roles import ROLE_ADMIN
|
||||
from app.core.roles import ROLE_ADMIN, ROLE_OEM,ROLE_AGENT
|
||||
from app.core.security import decode_access_token
|
||||
from app.database import get_db
|
||||
from app.models.user import User
|
||||
@@ -63,5 +63,23 @@ async def require_admin(current_user: CurrentUser) -> User:
|
||||
)
|
||||
return current_user
|
||||
|
||||
async def require_oem(current_user: CurrentUser) -> User:
|
||||
if current_user.role_id != ROLE_OEM:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="需要 OEM 权限",
|
||||
)
|
||||
return current_user
|
||||
|
||||
async def require_agent(current_user: CurrentUser) -> User:
|
||||
if current_user.role_id != ROLE_AGENT:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="需要代理权限",
|
||||
)
|
||||
return current_user
|
||||
|
||||
|
||||
AdminUser = Annotated[User, Depends(require_admin)]
|
||||
OemUser = Annotated[User, Depends(require_oem)]
|
||||
AgentUser = Annotated[User, Depends(require_agent)]
|
||||
|
||||
Reference in New Issue
Block a user