support: Make user search by email case-insensitive.

It's pretty troublesome to fail to find a user in our database because
they used a different capitalization when signing up.
This commit is contained in:
Mateusz Mandera 2023-05-16 13:47:56 +02:00 committed by Tim Abbott
parent 632e856240
commit 2b7877bcb4
2 changed files with 11 additions and 1 deletions

View File

@ -249,6 +249,12 @@ class TestSupportEndpoint(ZulipTestCase):
check_hamlet_user_query_result(result)
check_zulip_realm_query_result(result)
# Search should be case-insensitive:
assert self.example_email("hamlet") != self.example_email("hamlet").upper()
result = get_check_query_result(self.example_email("hamlet").upper(), 1)
check_hamlet_user_query_result(result)
check_zulip_realm_query_result(result)
result = get_check_query_result(lear_user.email, 1)
check_lear_user_query_result(result)
check_lear_realm_query_result(result)

View File

@ -9,6 +9,7 @@ from urllib.parse import urlencode
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.validators import URLValidator
from django.db.models import Q
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse
@ -289,7 +290,10 @@ def support(
if query:
key_words = get_invitee_emails_set(query)
users = set(UserProfile.objects.filter(delivery_email__in=key_words))
case_insensitive_users_q = Q()
for key_word in key_words:
case_insensitive_users_q |= Q(delivery_email__iexact=key_word)
users = set(UserProfile.objects.filter(case_insensitive_users_q))
realms = set(Realm.objects.filter(string_id__in=key_words))
for key_word in key_words: