mirror of https://github.com/zulip/zulip.git
find_account: Fix the email search query.
The search should be case-insensitive.
This commit is contained in:
parent
159641bab8
commit
bb46b21123
|
@ -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="iago@zulip.com,cordelia@zulip.com"))
|
||||
dict(emails="iago@zulip.com,cordeliA@zulip.com"))
|
||||
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("iago@zulip.com", content)
|
||||
self.assertIn("cordeliA@zulip.com", content)
|
||||
from django.core.mail import outbox
|
||||
|
||||
# 3 = 1 + 2 -- Cordelia gets an email each for the "zulip" and "lear" realms.
|
||||
|
|
|
@ -7,6 +7,7 @@ from django.conf import settings
|
|||
from django.contrib.auth import authenticate, get_backends
|
||||
from django.core import validators
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db.models import Q
|
||||
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import redirect, render
|
||||
from 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({
|
||||
|
|
Loading…
Reference in New Issue