Skip to content

Commit

Permalink
Fix email migration (#575)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
Rotheem authored Sep 10, 2024
1 parent b5022eb commit e0c8337
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down
11 changes: 1 addition & 10 deletions app/core/users/endpoints_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)


Expand Down
23 changes: 0 additions & 23 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]"},
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": "[email protected]"},
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
Expand Down

0 comments on commit e0c8337

Please sign in to comment.