Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
find_account: Fix the email search query.
Mateusz Manderabb46b21123dc
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 43fe5865074..125a7d98cb6 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -4128,15 +4128,16 @@ class TestFindMyTeam(ZulipTestCase):self.assertIn("Find your Zulip accounts", result.content.decode('utf8'))def test_result(self) -> None:+ # We capitalize a letter in cordelia's email to test that the search is case-insensitive.result = self.client_post('/accounts/find/',- dict(emails="[email protected],[email protected]"))+ dict(emails="[email protected],[email protected]"))self.assertEqual(result.status_code, 302)- self.assertEqual(result.url, "/accounts/find/?emails=iago%40zulip.com%2Ccordelia%40zulip.com")+ self.assertEqual(result.url, "/accounts/find/?emails=iago%40zulip.com%2CcordeliA%40zulip.com")result = self.client_get(result.url)content = result.content.decode('utf8')self.assertIn("Emails sent! You will only receive emails", content)- self.assertIn(self.example_email("iago"), content)- self.assertIn(self.example_email("cordelia"), content)+ self.assertIn("[email protected]", content)+ self.assertIn("[email protected]", content)from django.core.mail import outbox# 3 = 1 + 2 -- Cordelia gets an email each for the "zulip" and "lear" realms.diff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex eb71cfa5865..fed947f3b45 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -7,6 +7,7 @@ from django.conf import settingsfrom django.contrib.auth import authenticate, get_backendsfrom django.core import validatorsfrom django.core.exceptions import ValidationError+from django.db.models import Qfrom django.http import HttpRequest, HttpResponse, HttpResponseRedirectfrom django.shortcuts import redirect, renderfrom django.urls import reverse@@ -601,8 +602,15 @@ def find_account(request: HttpRequest) -> HttpResponse:form = FindMyTeamForm(request.POST)if form.is_valid():emails = form.cleaned_data['emails']++ # Django doesn't support __iexact__in lookup with EmailField, so we have+ # to use Qs to get around that without needing to do multiple queries.+ emails_q = Q()+ for email in emails:+ emails_q |= Q(delivery_email__iexact=email)+for user in UserProfile.objects.filter(- delivery_email__in=emails, is_active=True, is_bot=False,+ emails_q, is_active=True, is_bot=False,realm__deactivated=False):context = common_context(user)context.update({