feat: org exists checks on orguser routes
Routes modifying the org-user table did not check if the org existed first.
This commit is contained in:
parent
6f4556a44b
commit
d89c926a38
1 changed files with 9 additions and 1 deletions
|
|
@ -141,6 +141,10 @@ async def get_admin_users(db: db_dependency, org_id: Annotated[int, Path(gt=0)])
|
||||||
|
|
||||||
@router.post("/{org_id}/users")
|
@router.post("/{org_id}/users")
|
||||||
async def add_user_to_org(db: db_dependency, user_request: OrgUserPostRequest, org_id: Annotated[int, Path(gt=0)]):
|
async def add_user_to_org(db: db_dependency, user_request: OrgUserPostRequest, org_id: Annotated[int, Path(gt=0)]):
|
||||||
|
org_model = (db.query(Org).filter(Org.id == org_id).first())
|
||||||
|
if org_model is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Organisation not found")
|
||||||
|
|
||||||
org_user_model = OrgUsers(**user_request.model_dump(), org_id=org_id)
|
org_user_model = OrgUsers(**user_request.model_dump(), org_id=org_id)
|
||||||
|
|
||||||
db.add(org_user_model)
|
db.add(org_user_model)
|
||||||
|
|
@ -152,7 +156,10 @@ async def update_user_details(db: db_dependency, user_request: OrgUserPostReques
|
||||||
"""
|
"""
|
||||||
Currently used only to update user admin status for organisation.
|
Currently used only to update user admin status for organisation.
|
||||||
"""
|
"""
|
||||||
# TODO: Check if org exists
|
org_model = (db.query(Org).filter(Org.id == org_id).first())
|
||||||
|
if org_model is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Organisation not found")
|
||||||
|
|
||||||
org_user_model = db.query(OrgUsers).filter(OrgUsers.org_id == org_id).filter(OrgUsers.user_id == user_request.user_id).first()
|
org_user_model = db.query(OrgUsers).filter(OrgUsers.org_id == org_id).filter(OrgUsers.user_id == user_request.user_id).first()
|
||||||
|
|
||||||
if org_user_model is None:
|
if org_user_model is None:
|
||||||
|
|
@ -179,6 +186,7 @@ async def get_contact(db: db_dependency, contact_type: ContactType, org_id: Anno
|
||||||
org_model = db.query(Org).filter(Org.id == org_id).first()
|
org_model = db.query(Org).filter(Org.id == org_id).first()
|
||||||
if org_model is None:
|
if org_model is None:
|
||||||
raise HTTPException(status_code=404, detail="Organisation not found")
|
raise HTTPException(status_code=404, detail="Organisation not found")
|
||||||
|
|
||||||
match contact_type:
|
match contact_type:
|
||||||
case "billing":
|
case "billing":
|
||||||
contact_id = org_model.billing_contact_id
|
contact_id = org_model.billing_contact_id
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue