Skip to content

Commit

Permalink
fix(backend): get org_id from db_org (org) from dependency org_admin …
Browse files Browse the repository at this point in the history
…and delete org managers on deletion of org
  • Loading branch information
Sujanadh committed Nov 11, 2024
1 parent da3f02f commit 9e5baa6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/backend/app/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,11 @@ async def delete(cls, db: Connection, org_id: int) -> bool:
DELETE FROM projects
WHERE organisation_id = %(org_id)s
RETURNING organisation_id
), deleted_org AS (
), deleted_org_managers AS (
DELETE FROM organisation_managers
WHERE organisation_id = %(org_id)s
RETURNING organisation_id
),deleted_org AS (
DELETE FROM organisations
WHERE id = %(org_id)s
RETURNING id
Expand Down
7 changes: 4 additions & 3 deletions src/backend/app/organisations/organisation_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ async def delete_org(
org_user_dict: Annotated[AuthUser, Depends(org_admin)],
):
"""Delete an organisation."""
org_deleted = await DbOrganisation.delete(db, org_user_dict.id)
org = org_user_dict.get("org")
org_deleted = await DbOrganisation.delete(db, org.id)
if not org_deleted:
log.error(f"Failed deleting org ({org_user_dict.name}).")
log.error(f"Failed deleting org ({org.name}).")
raise HTTPException(
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
detail=f"Failed deleting org ({org_user_dict.name}).",
detail=f"Failed deleting org ({org.name}).",
)
return Response(status_code=HTTPStatus.NO_CONTENT)

Expand Down

0 comments on commit 9e5baa6

Please sign in to comment.