diff --git a/apps/betterangels-backend/accounts/models.py b/apps/betterangels-backend/accounts/models.py index 6119b1139..e24fbfda2 100644 --- a/apps/betterangels-backend/accounts/models.py +++ b/apps/betterangels-backend/accounts/models.py @@ -102,6 +102,12 @@ def is_outreach_authorized(self: "User") -> bool: organization__in=user_organizations, template__name__in=authorized_permission_groups ).exists() + def save(self, *args: Any, **kwargs: Any) -> None: + if self.email: + self.email = self.email.lower() + + super().save(*args, **kwargs) + class ExtendedOrganizationInvitation(OrganizationInvitation): accepted = models.BooleanField(default=False) diff --git a/apps/betterangels-backend/accounts/tests/test_models.py b/apps/betterangels-backend/accounts/tests/test_models.py index 9253708ae..be3d2b459 100644 --- a/apps/betterangels-backend/accounts/tests/test_models.py +++ b/apps/betterangels-backend/accounts/tests/test_models.py @@ -51,3 +51,7 @@ def test_is_outreach_authorized( remove_organization_permission_group(unauthorized_org) self.assertEqual(user.is_outreach_authorized, should_succeed) + + def test_save(self) -> None: + user = User.objects.create(username="lowercaseme", email="LOWERCASEME@EXAMPLE.COM") + self.assertEqual(user.email, "lowercaseme@example.com")