feat: custom exceptions instead of direct fastapi.httpexceptions
Resolves #2
This commit is contained in:
parent
d3d3b2ca63
commit
868e56ce40
9 changed files with 73 additions and 43 deletions
|
|
@ -10,18 +10,19 @@ Functions:
|
|||
- Functions: Description
|
||||
"""
|
||||
from typing import Annotated, Any
|
||||
from fastapi import Depends, HTTPException
|
||||
from fastapi import Depends
|
||||
|
||||
from src.user.dependencies import user_model_claims_dependency
|
||||
|
||||
from src.organisation.dependencies import org_model_query_dependency
|
||||
|
||||
from src.auth.exceptions import UnauthorizedException
|
||||
|
||||
|
||||
async def org_query_user_claims(org_model: org_model_query_dependency, user_model: user_model_claims_dependency):
|
||||
if user_model in org_model.user_rel:
|
||||
return True
|
||||
|
||||
raise HTTPException(status_code=401, detail="Not authorised")
|
||||
raise UnauthorizedException()
|
||||
|
||||
|
||||
org_query_user_claims_dependency = Annotated[dict[str, Any], Depends(org_query_user_claims)]
|
||||
|
|
@ -31,7 +32,7 @@ async def org_query_root_claims(user_model: user_model_claims_dependency, org_mo
|
|||
if org_model.root_user_id == user_model.id:
|
||||
return True
|
||||
|
||||
raise HTTPException(status_code=401, detail="Not authorised")
|
||||
raise UnauthorizedException()
|
||||
|
||||
|
||||
org_query_root_claims_dependency = Annotated[dict[str, Any], Depends(org_query_root_claims)]
|
||||
|
|
@ -40,8 +41,7 @@ org_query_root_claims_dependency = Annotated[dict[str, Any], Depends(org_query_r
|
|||
async def is_super_admin(user_model: user_model_claims_dependency):
|
||||
super_admin_emails = []
|
||||
if user_model.email not in super_admin_emails:
|
||||
raise HTTPException(status_code=401, detail="Not authorised")
|
||||
|
||||
raise UnauthorizedException()
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue