48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
"""
|
|
Router dependencies for auth module
|
|
|
|
Classes:
|
|
- List: Description
|
|
- Classes: Description
|
|
|
|
Functions:
|
|
- List: Description
|
|
- Functions: Description
|
|
"""
|
|
from typing import Annotated, Any
|
|
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 UnauthorizedException()
|
|
|
|
|
|
org_query_user_claims_dependency = Annotated[dict[str, Any], Depends(org_query_user_claims)]
|
|
|
|
|
|
async def org_query_root_claims(user_model: user_model_claims_dependency, org_model: org_model_query_dependency):
|
|
if org_model.root_user_id == user_model.id:
|
|
return True
|
|
|
|
raise UnauthorizedException()
|
|
|
|
|
|
org_query_root_claims_dependency = Annotated[dict[str, Any], Depends(org_query_root_claims)]
|
|
|
|
|
|
async def is_super_admin(user_model: user_model_claims_dependency):
|
|
super_admin_emails = []
|
|
if user_model.email not in super_admin_emails:
|
|
raise UnauthorizedException()
|
|
return True
|
|
|
|
|
|
super_admin_dependency = Annotated[dict[str, Any], Depends(is_super_admin)]
|