From 91170430ff9fc55c5e0d84ae52be42ab7d90ebe5 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Sat, 5 Nov 2022 17:48:31 +0000 Subject: [PATCH] fix: Check both Person and Email records in profile view (#4703) --- ietf/person/tests.py | 22 +++++++++++++++++----- ietf/person/views.py | 10 ++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ietf/person/tests.py b/ietf/person/tests.py index f659b98963..be330bdf0d 100644 --- a/ietf/person/tests.py +++ b/ietf/person/tests.py @@ -104,6 +104,23 @@ def test_person_profile(self): r = self.client.get(photo_url) self.assertEqual(r.status_code, 200) + def test_person_profile_without_email(self): + person = PersonFactory(name="foobar@example.com") + # delete Email record + person.email().delete() + url = urlreverse("ietf.person.views.profile", kwargs={ "email_or_name": person.plain_name()}) + r = self.client.get(url) + self.assertContains(r, person.name, status_code=200) + + def test_person_profile_404(self): + urls = [ + urlreverse("ietf.person.views.profile", kwargs={ "email_or_name": "nonexistent@example.com"}), + urlreverse("ietf.person.views.profile", kwargs={ "email_or_name": "Nonexistent Person"}),] + + for url in urls: + r = self.client.get(url) + self.assertEqual(r.status_code, 404) + def test_person_photo(self): person = PersonFactory(with_bio=True) @@ -403,8 +420,3 @@ def test_dots(self): self.assertEqual(get_dots(ncmember),['nomcom']) ncchair = RoleFactory(group__acronym='nomcom2020',group__type_id='nomcom',name_id='chair').person self.assertEqual(get_dots(ncchair),['nomcom']) - - - - - \ No newline at end of file diff --git a/ietf/person/views.py b/ietf/person/views.py index 59ab9366c4..7ac300cae2 100644 --- a/ietf/person/views.py +++ b/ietf/person/views.py @@ -68,11 +68,13 @@ def ajax_select2_search(request, model_name): return HttpResponse(select2_id_name_json(objs), content_type='application/json') def profile(request, email_or_name): + aliases = Alias.objects.filter(name=email_or_name) + persons = list(set([ a.person for a in aliases ])) + if '@' in email_or_name: - persons = [ get_object_or_404(Email, address=email_or_name).person, ] - else: - aliases = Alias.objects.filter(name=email_or_name) - persons = list(set([ a.person for a in aliases ])) + emails = Email.objects.filter(address=email_or_name) + persons += list(set([ e.person for e in emails ])) + persons = [ p for p in persons if p and p.id ] if not persons: raise Http404