current or admin dep created
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import HTTPException, Depends
|
||||
from fastapi import HTTPException, Depends, Path
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
from jwt import InvalidTokenError
|
||||
|
||||
@@ -49,3 +49,24 @@ async def get_admin_user(db: sessionDep, current_user: ActiveUser):
|
||||
|
||||
|
||||
AdminUser = Annotated[TokenData, Depends(get_admin_user)]
|
||||
|
||||
|
||||
async def user_or_admin_path(db: sessionDep, id: int, current_user: ActiveUser):
|
||||
if current_user.id == id:
|
||||
return current_user
|
||||
else:
|
||||
admin = await get_admin_user(db, current_user)
|
||||
return admin
|
||||
|
||||
|
||||
async def user_or_admin(
|
||||
db: sessionDep, current_user: ActiveUser, id: Annotated[int, Path()]
|
||||
):
|
||||
if current_user.id == id:
|
||||
return current_user
|
||||
else:
|
||||
admin = await get_admin_user(db, current_user)
|
||||
return admin
|
||||
|
||||
|
||||
CurrentOrAdmin = Annotated[TokenData, Depends(user_or_admin)]
|
||||
|
||||
Reference in New Issue
Block a user