Skip to content

Commit 3b08ba4

Browse files
committed
♻️(backend) force saving invitation email in lowercase
We want to enforce that invitation email are saved in lower case.
1 parent 590b67f commit 3b08ba4

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/backend/core/api/serializers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,8 @@ def validate(self, attrs):
740740
if self.instance is None:
741741
attrs["issuer"] = user
742742

743+
attrs["email"] = attrs["email"].lower()
744+
743745
return attrs
744746

745747
def validate_role(self, role):

src/backend/core/tests/documents/test_api_document_invitations.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,32 @@ def test_api_document_invitations_create_cannot_invite_existing_users():
596596
}
597597

598598

599+
def test_api_document_invitations_create_lower_email():
600+
"""
601+
No matter the case, the email should be converted to lowercase.
602+
"""
603+
user = factories.UserFactory()
604+
document = factories.DocumentFactory(users=[(user, "owner")])
605+
606+
# Build an invitation to the email of an existing identity in the db
607+
invitation_values = {
608+
"email": "[email protected]",
609+
"role": random.choice(models.RoleChoices.values),
610+
}
611+
612+
client = APIClient()
613+
client.force_login(user)
614+
615+
response = client.post(
616+
f"/api/v1.0/documents/{document.id!s}/invitations/",
617+
invitation_values,
618+
format="json",
619+
)
620+
621+
assert response.status_code == 201
622+
assert response.json()["email"] == "[email protected]"
623+
624+
599625
# Update
600626

601627

0 commit comments

Comments
 (0)