♻️(backend) force saving invitation email in lowercase
We want to enforce that invitation email are saved in lower case.
This commit is contained in:
@@ -740,6 +740,8 @@ class InvitationSerializer(serializers.ModelSerializer):
|
|||||||
if self.instance is None:
|
if self.instance is None:
|
||||||
attrs["issuer"] = user
|
attrs["issuer"] = user
|
||||||
|
|
||||||
|
attrs["email"] = attrs["email"].lower()
|
||||||
|
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def validate_role(self, role):
|
def validate_role(self, role):
|
||||||
|
|||||||
@@ -596,6 +596,32 @@ def test_api_document_invitations_create_cannot_invite_existing_users():
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_document_invitations_create_lower_email():
|
||||||
|
"""
|
||||||
|
No matter the case, the email should be converted to lowercase.
|
||||||
|
"""
|
||||||
|
user = factories.UserFactory()
|
||||||
|
document = factories.DocumentFactory(users=[(user, "owner")])
|
||||||
|
|
||||||
|
# Build an invitation to the email of an existing identity in the db
|
||||||
|
invitation_values = {
|
||||||
|
"email": "GuEst@example.com",
|
||||||
|
"role": random.choice(models.RoleChoices.values),
|
||||||
|
}
|
||||||
|
|
||||||
|
client = APIClient()
|
||||||
|
client.force_login(user)
|
||||||
|
|
||||||
|
response = client.post(
|
||||||
|
f"/api/v1.0/documents/{document.id!s}/invitations/",
|
||||||
|
invitation_values,
|
||||||
|
format="json",
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 201
|
||||||
|
assert response.json()["email"] == "guest@example.com"
|
||||||
|
|
||||||
|
|
||||||
# Update
|
# Update
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user