fix: drop duplicate alias/email Person records from profile view (#4734)

* fix: drop duplicate alias/email Person records from profile view

* test: test de-duplication of Person records
This commit is contained in:
Jennifer Richards 2022-11-08 13:48:17 -04:00 committed by GitHub
parent 86191c4a38
commit 131cdf9943
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View file

@ -112,6 +112,23 @@ class PersonTests(TestCase):
r = self.client.get(url)
self.assertContains(r, person.name, status_code=200)
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")
url = urlreverse("ietf.person.views.profile", kwargs={ "email_or_name": person.plain_name()})
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertNotIn('More than one person', r.content.decode())
# Change that person's name but leave their email address. Create a new person whose name
# is the email address. This *should* be flagged as multiple Person records on the profile.
person.name = 'different name'
person.save()
PersonFactory(name="bazquux@example.com")
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
self.assertIn('More than one person', r.content.decode())
def test_person_profile_404(self):
urls = [
urlreverse("ietf.person.views.profile", kwargs={ "email_or_name": "nonexistent@example.com"}),

View file

@ -67,17 +67,19 @@ 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 ]))
persons = set(a.person for a in aliases)
if '@' in email_or_name:
emails = Email.objects.filter(address=email_or_name)
persons += list(set([ e.person for e in emails ]))
persons.update(e.person for e in emails)
persons = [ p for p in persons if p and p.id ]
persons = [p for p in persons if p and p.id]
if not persons:
raise Http404
persons.sort(key=lambda p: p.id)
return render(request, 'person/profile.html', {'persons': persons, 'today': timezone.now()})