From e0c8337def67e328eb3835c4b03ab877a96be469 Mon Sep 17 00:00:00 2001 From: Rotheem <114694873+Rotheem@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:24:30 +0200 Subject: [PATCH] Fix email migration (#575) ### Description Please explain the changes you made here. ### Checklist - [ ] Created tests which fail without the change (if possible) - [ ] All tests passing - [ ] Extended the documentation, if necessary --- app/core/config.py | 4 ++-- app/core/users/endpoints_users.py | 11 +---------- tests/test_users.py | 23 ----------------------- 3 files changed, 3 insertions(+), 35 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index 1937b5287..0646d624f 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -192,8 +192,8 @@ class Settings(BaseSettings): # Hyperion follows Semantic Versioning # https://semver.org/ - HYPERION_VERSION: str = "3.0.2" - MINIMAL_TITAN_VERSION_CODE: int = 113 + HYPERION_VERSION: str = "3.0.3" + MINIMAL_TITAN_VERSION_CODE: int = 130 ###################################### # Automatically generated parameters # diff --git a/app/core/users/endpoints_users.py b/app/core/users/endpoints_users.py index dc38635f6..9dd2a84ab 100644 --- a/app/core/users/endpoints_users.py +++ b/app/core/users/endpoints_users.py @@ -612,15 +612,6 @@ async def migrate_mail( This endpoint will send a confirmation code to the user's new email address. He will need to use this code to confirm the change with `/users/confirm-mail-migration` endpoint. """ - if not re.match( - r"^[\w\-.]*@((ecl\d{2})|(alternance\d{4})|(master)|(auditeur))\.ec-lyon\.fr$", - user.email, - ): - raise HTTPException( - status_code=400, - detail="Only student users with an old email address can migrate their email address", - ) - if not re.match(r"^[\w\-.]*@etu(-enise)?\.ec-lyon\.fr$", mail_migration.new_email): raise HTTPException( status_code=400, @@ -653,7 +644,7 @@ async def migrate_mail( old_email=user.email, db=db, settings=settings, - make_user_external=user.external, + make_user_external=False, ) diff --git a/tests/test_users.py b/tests/test_users.py index cd67ae691..8f4abfa0c 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -258,29 +258,6 @@ def test_update_user(client: TestClient) -> None: assert response.status_code == 204 -async def test_invalid_migrate_mail(client: TestClient) -> None: - student_user_with_old_email_token = create_api_access_token( - student_user_with_old_email, - ) - other_student_user_token = create_api_access_token(student_user) - - # Invalid old mail format - response = client.post( - "/users/migrate-mail", - json={"new_email": "fabristpp.eclair@etu.ec-lyon.fr"}, - headers={"Authorization": f"Bearer {other_student_user_token}"}, - ) - assert response.status_code == 400 - - # Invalid new mail format - response = client.post( - "/users/migrate-mail", - json={"new_email": "fabristpp.eclair@test.fr"}, - headers={"Authorization": f"Bearer {student_user_with_old_email_token}"}, - ) - assert response.status_code == 400 - - async def test_migrate_mail(mocker: MockerFixture, client: TestClient) -> None: # NOTE: we don't want to mock app.core.security.generate_token but # app.core.users.endpoints_users.security.generate_token which is the imported version of the function