From 53ae46b0040ef8e31c75857ffb0cfdb3bd1b2fe8 Mon Sep 17 00:00:00 2001 From: Rich Salz Date: Sat, 22 Jul 2023 13:51:27 -0400 Subject: [PATCH] fix: Make name/email lookups case-insensitive (#5972) Use icontains so that looking up name or email is case insensitive Added a test Fixes: 5972 --- ietf/person/tests.py | 8 ++++++++ ietf/person/views.py | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ietf/person/tests.py b/ietf/person/tests.py index 11e1a5b663..bb75b438db 100644 --- a/ietf/person/tests.py +++ b/ietf/person/tests.py @@ -112,6 +112,14 @@ def test_person_profile_without_email(self): r = self.client.get(url) self.assertContains(r, person.name, status_code=200) + def test_case_insensitive(self): + # Case insensitive seach + person = PersonFactory(name="Test Person") + url = urlreverse("ietf.person.views.profile", kwargs={ "email_or_name": "test person"}) + r = self.client.get(url) + self.assertContains(r, person.name, status_code=200) + self.assertNotIn('More than one person', r.content.decode()) + def test_person_profile_duplicates(self): # same Person name and email - should not show on the profile as multiple Person records person = PersonFactory(name="bazquux@example.com", user__email="bazquux@example.com") diff --git a/ietf/person/views.py b/ietf/person/views.py index 4e3f7d8c30..eed92f21e7 100644 --- a/ietf/person/views.py +++ b/ietf/person/views.py @@ -69,11 +69,11 @@ def ajax_select2_search(request, model_name): def profile(request, email_or_name): - aliases = Alias.objects.filter(name=email_or_name) + aliases = Alias.objects.filter(name__icontains=email_or_name) persons = set(a.person for a in aliases) if '@' in email_or_name: - emails = Email.objects.filter(address=email_or_name) + emails = Email.objects.filter(address__icontains=email_or_name) persons.update(e.person for e in emails) persons = [p for p in persons if p and p.id]