Skip to content

Commit

Permalink
fix: Make name/email lookups case-insensitive (ietf-tools#5972)
Browse files Browse the repository at this point in the history
Use icontains so that looking up name or email is case insensitive
Added a test

Fixes: 5972
  • Loading branch information
richsalz committed Jul 22, 2023
1 parent a38b6c1 commit 53ae46b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions ietf/person/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]", user__email="[email protected]")
Expand Down
4 changes: 2 additions & 2 deletions ietf/person/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 53ae46b

Please sign in to comment.