Skip to content

Commit

Permalink
Merge pull request #1760 from fractal-analytics-platform/1757-re-inst…
Browse files Browse the repository at this point in the history
…ate-check-of-existing-email-address-in-patch-authusersid

Re-add check of existing-user in `PATCH /auth/users/{id}/`
  • Loading branch information
tcompa authored Sep 12, 2024
2 parents db54dd9 + 11148d9 commit a05e306
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
**Note**: Numbers like (\#1234) point to closed Pull Requests on the fractal-server repository.

# 2.4.1

* API:
* Re-introduce check for existing-user-email in `PATCH /auth/users/{id}/` (\#1760).

# 2.4.0

* App:
Expand Down
5 changes: 5 additions & 0 deletions fractal_server/app/routes/auth/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ async def patch_user(
"reason": e.reason,
},
)
except exceptions.UserAlreadyExists:
raise HTTPException(
status.HTTP_400_BAD_REQUEST,
detail=ErrorCode.UPDATE_USER_EMAIL_ALREADY_EXISTS,
)
else:
# Nothing to do, just continue
patched_user = user_to_patch
Expand Down
16 changes: 16 additions & 0 deletions tests/no_version/test_auth_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,22 @@ async def test_edit_users_as_superuser(registered_superuser_client):
)
assert res.status_code == 422

# Setting the email to an existing one fails with 4
res = await registered_superuser_client.get(
f"{PREFIX}/users/",
)
assert res.status_code == 200
users = res.json()
assert len(users) == 2
user_0_id = users[0]["id"]
user_1_email = users[1]["email"]
res = await registered_superuser_client.patch(
f"{PREFIX}/users/{user_0_id}/",
json=dict(email=user_1_email),
)
assert res.status_code == 400
assert "UPDATE_USER_EMAIL_ALREADY_EXISTS" == res.json()["detail"]

for attribute in ["email", "is_active", "is_superuser", "is_verified"]:
res = await registered_superuser_client.patch(
f"{PREFIX}/users/{user_id}/",
Expand Down

0 comments on commit a05e306

Please sign in to comment.