feat: auth dependencies
These dependencies require `user_model_claims_dependency` which requires the `claims_dependency`. This caused an import loop error and therefore they must be defined in a different file from `claims_dependency`. Resolves #6
This commit is contained in:
parent
75f5bc79da
commit
d3d3b2ca63
3 changed files with 40 additions and 63 deletions
|
|
@ -8,4 +8,41 @@ Classes:
|
|||
Functions:
|
||||
- List: Description
|
||||
- Functions: Description
|
||||
"""
|
||||
"""
|
||||
from typing import Annotated, Any
|
||||
from fastapi import Depends, HTTPException
|
||||
|
||||
from src.user.dependencies import user_model_claims_dependency
|
||||
|
||||
from src.organisation.dependencies import org_model_query_dependency
|
||||
|
||||
|
||||
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")
|
||||
|
||||
|
||||
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 HTTPException(status_code=401, detail="Not authorised")
|
||||
|
||||
|
||||
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 HTTPException(status_code=401, detail="Not authorised")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
super_admin_dependency = Annotated[dict[str, Any], Depends(is_super_admin)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue