-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix create and delete organisation #1867
Changes from 2 commits
9a9e44f
da3f02f
9e5baa6
5876566
75e3e25
94c5e02
4fdc84e
335a522
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,8 @@ async def get_organisation( | |
pass | ||
db_org = await DbOrganisation.one(db, id) | ||
|
||
if db_org is None: | ||
raise KeyError(f"Organisation ({id}) not found.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was moving this related to the 'my organisations' endpoint? The logic is a bit duplicated now though, as you could probably just raise a HTTPException without needing the KeyError. Is it possible to keep the KeyError in the model There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see, I got your point. But the reason why I removed it from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah that makes sense π I'm not on my laptop to really dig into the logic. But it work using the We just need to ideally check if the name already exists on creation, but don't need to get the org with (just be sure that removing the keyerror doesn't break logic elsewhere) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we need to check if that name already exists, so we need to write SQL again to check it in the create function. Or, we might create a new function to check if the organisation exists or not and use it in other endpoints too. We already have the |
||
except KeyError as e: | ||
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail=str(e)) from e | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
APIRouter, | ||
Depends, | ||
File, | ||
HTTPException, | ||
Response, | ||
UploadFile, | ||
) | ||
|
@@ -99,7 +100,7 @@ async def create_organisation( | |
Either a logo can be uploaded, or a link to the logo provided | ||
in the Organisation JSON ('logo': 'https://your.link.to.logo.png'). | ||
""" | ||
return DbOrganisation.create(db, org_in, current_user.id, logo) | ||
return await DbOrganisation.create(db, org_in, current_user.id, logo) | ||
|
||
|
||
@router.patch("/{org_id}/", response_model=OrganisationOut) | ||
|
@@ -120,19 +121,14 @@ async def delete_org( | |
org_user_dict: Annotated[AuthUser, Depends(org_admin)], | ||
): | ||
"""Delete an organisation.""" | ||
org = org_user_dict.get("org") | ||
deleted_org_id = await DbOrganisation.delete(db, org.id) | ||
|
||
if not deleted_org_id: | ||
return Response( | ||
org_deleted = await DbOrganisation.delete(db, org_user_dict.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe org_user_dict actually has keys org_user_id.get("org").id There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeah actually, I tested and overdid it while refactoring without noticing. Thanks for pointing out. |
||
if not org_deleted: | ||
log.error(f"Failed deleting org ({org_user_dict.name}).") | ||
raise HTTPException( | ||
status_code=HTTPStatus.UNPROCESSABLE_ENTITY, | ||
details=f"Failed deleting org {(org.name)}.", | ||
detail=f"Failed deleting org ({org_user_dict.name}).", | ||
) | ||
|
||
return Response( | ||
status_code=HTTPStatus.NO_CONTENT, | ||
details=f"Deleted org {(org.deleted_org_id)}.", | ||
) | ||
return Response(status_code=HTTPStatus.NO_CONTENT) | ||
|
||
|
||
@router.delete("/unapproved/{org_id}") | ||
|
@@ -148,11 +144,17 @@ async def delete_unapproved_org( | |
will also check if the organisation is approved and error if it's not. | ||
This is an ADMIN-only endpoint for deleting unapproved orgs. | ||
""" | ||
await DbOrganisation.delete(db, org_id) | ||
return Response( | ||
status_code=HTTPStatus.NO_CONTENT, | ||
detail=f"Deleted org ({org_id}).", | ||
) | ||
org_deleted = await DbOrganisation.delete(db, org_id) | ||
|
||
if not org_deleted: | ||
log.error(f"Failed deleting org ({org_id}).") | ||
raise HTTPException( | ||
status_code=HTTPStatus.UNPROCESSABLE_ENTITY, | ||
detail=f"Failed deleting org ({org_id}).", | ||
) | ||
|
||
log.info(f"Successfully deleted org ({org_id}).") | ||
return Response(status_code=HTTPStatus.NO_CONTENT) | ||
|
||
|
||
@router.post("/approve/", response_model=OrganisationOut) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ignore_conflict used anywhere now?
I forgot why I added it in the first place.
Perhaps it can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is used in the init default HOTOSM organisation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is still there in SQL to create an organization.