Skip to content

Commit

Permalink
fix: Check both Person and Email records in profile view (#4703)
Browse files Browse the repository at this point in the history
  • Loading branch information
kesara authored Nov 5, 2022
1 parent eee6d01 commit 9117043
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
22 changes: 17 additions & 5 deletions ietf/person/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]")
# 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": "[email protected]"}),
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)

Expand Down Expand Up @@ -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'])





10 changes: 6 additions & 4 deletions ietf/person/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9117043

Please sign in to comment.