feat: org dependencies
Org endpoints use query/body model dependencies to perform initial db lookups. Issue #6 Org ID path params have been replaced with either query params (get endpoints) or body values. Resolves #10 Endpoints in other modules that rely on an org model lookup have also been updated.
This commit is contained in:
parent
c6a2b301dc
commit
657f91d73d
9 changed files with 106 additions and 74 deletions
|
|
@ -22,7 +22,7 @@ from src.user.service import add_user_to_db
|
|||
from src.organisation.models import OrgUsers, Organisation as Org
|
||||
from src.user.models import User
|
||||
from src.database import db_dependency
|
||||
from src.organisation.dependencies import org_model_dependency
|
||||
from src.organisation.dependencies import org_model_query_dependency
|
||||
|
||||
|
||||
oidc = OpenIdConnect(openIdConnectUrl=auth_settings.OIDC_CONFIG)
|
||||
|
|
@ -54,7 +54,7 @@ async def get_current_user(oidc_auth_string: oidc_dependency) -> dict[str, Any]:
|
|||
|
||||
try:
|
||||
claims_requests.validate(token.claims)
|
||||
except ExpiredTokenError as e:
|
||||
except ExpiredTokenError:
|
||||
raise HTTPException(status_code=401, detail="Token expired")
|
||||
|
||||
db_id = await add_user_to_db(token.claims)
|
||||
|
|
@ -93,7 +93,7 @@ async def is_org_user(claims: claims_dependency, db: db_dependency, org_id: int
|
|||
org_user_dependency = Annotated[dict[str, Any], Depends(is_org_user)]
|
||||
|
||||
|
||||
async def is_org_root(claims: claims_dependency, db: db_dependency, org_model: org_model_dependency, org_id: int = Path(gt=0)):
|
||||
async def is_org_root_query(claims: claims_dependency, db: db_dependency, org_model: org_model_query_dependency):
|
||||
db_id = claims.get("db_id", None)
|
||||
if db_id is None:
|
||||
raise HTTPException(status_code=404, detail="User not found in db")
|
||||
|
|
@ -104,7 +104,7 @@ async def is_org_root(claims: claims_dependency, db: db_dependency, org_model: o
|
|||
raise HTTPException(status_code=401, detail="Not authorised")
|
||||
|
||||
|
||||
root_user_dependency = Annotated[dict[str, Any], Depends(is_org_root)]
|
||||
root_user_query_dependency = Annotated[dict[str, Any], Depends(is_org_root_query)]
|
||||
|
||||
|
||||
async def is_super_admin(claims: claims_dependency):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue