feat: combined admin dependency
org_or_super_admin_dependency can be used in place of org_admin_dependency to also allow super admins.
This commit is contained in:
parent
34cb4414c9
commit
2b8296d622
1 changed files with 12 additions and 0 deletions
|
|
@ -126,7 +126,19 @@ async def is_super_admin(claims: claims_dependency):
|
|||
super_admin_dependency = Annotated[dict[str, Any], Depends(is_super_admin)]
|
||||
|
||||
|
||||
async def is_admin(claims: claims_dependency, db: db_dependency, org_id: int = Path(gt=0)):
|
||||
try:
|
||||
await is_super_admin(claims)
|
||||
return True
|
||||
except HTTPException as e:
|
||||
pass
|
||||
try:
|
||||
await is_org_admin(claims, db, org_id)
|
||||
return True
|
||||
except HTTPException as e:
|
||||
raise HTTPException(status_code=401, detail="Not authorised")
|
||||
|
||||
org_or_super_admin_dependency = Annotated[dict[str, Any], Depends(is_admin)]
|
||||
|
||||
# Middleware version of user auth
|
||||
# import json
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue