From 2bcffdcc327e899bb2c9dcf46df414ffc6746143 Mon Sep 17 00:00:00 2001 From: jonfroehlich Date: Tue, 1 Dec 2026 07:09:22 -0800 Subject: [PATCH 1/2] Hide private projects from auto-generated member bios The auto-generated bio on public member pages listed every project a person has a role on, including hidden (is_visible=False/None) ones. Filter to visible projects, matching the truthy check used by views.member.get_member_projects. Adds regression tests for a mix of visible/hidden projects and for a person whose only projects are hidden. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HFUXRa2hBVnK4hXzY8dK68 --- website/tests/test_bio_utils.py | 33 ++++++++++++++++++++++++++++++++- website/utils/bio_utils.py | 9 ++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/website/tests/test_bio_utils.py b/website/tests/test_bio_utils.py index 13807eff..1a3444a8 100644 --- a/website/tests/test_bio_utils.py +++ b/website/tests/test_bio_utils.py @@ -99,10 +99,11 @@ def _make_link_person(first_name, last_name, url_name): return p -def _make_project(name, short_name): +def _make_project(name, short_name, is_visible=True): p = MagicMock() p.name = name p.short_name = short_name + p.is_visible = is_visible return p @@ -283,6 +284,36 @@ def test_one_project_no_pubs(self): self.assertIn("They contributed to a project called Sound Watch.", bio) + def test_hidden_projects_are_not_named(self): + """Hidden (private) projects must not leak into the public bio.""" + projs = [ + _make_project("Public One", "publicone"), + _make_project("Secret", "secret", is_visible=False), + _make_project("Unset", "unset", is_visible=None), + ] + person = _make_person( + is_current_member=True, + is_active=True, + current_title="Undergrad", + projects=projs, + ) + bio = auto_generate_bio(person) + self.assertIn("a project called Public One", bio) + self.assertNotIn("Secret", bio) + self.assertNotIn("Unset", bio) + + def test_only_hidden_projects_and_no_pubs_has_no_contributions(self): + person = _make_person( + is_current_member=True, + is_active=True, + current_title="Undergrad", + projects=[_make_project("Secret", "secret", is_visible=False)], + ) + bio = auto_generate_bio(person) + self.assertNotIn("contributed to", bio) + self.assertNotIn("Secret", bio) + def test_two_projects_uses_and(self): projs = [ _make_project("Alpha", "alpha"), diff --git a/website/utils/bio_utils.py b/website/utils/bio_utils.py index 8abd6c81..f3c77730 100644 --- a/website/utils/bio_utils.py +++ b/website/utils/bio_utils.py @@ -143,7 +143,14 @@ def _contributions_sentence(person): with "including" + the first three. Publication count is appended as a plain count rather than a list. """ - projects = sorted(person.get_projects, key=lambda p: p.name) + # Only name publicly visible projects: this bio renders on the public + # member page, and hidden (private) projects must not leak there. Matches + # the truthy check in views.member.get_member_projects (is_visible may be + # None, which is treated as hidden). + projects = sorted( + (p for p in person.get_projects if p.is_visible), + key=lambda p: p.name, + ) proj_count = len(projects) pub_count = person.publication_set.count() From 5299c5c193975e42c24469eba1448b4d739ae881 Mon Sep 17 00:00:00 2001 From: jonfroehlich Date: Tue, 1 Dec 2026 10:55:46 -0800 Subject: [PATCH 2/2] Bio visibility: DB-backed regression test, tighter mock fixtures Review round 1 on PR 1469: - Add MemberBioVisibilityTests, a DatabaseTestCase that renders the real member page for a person on a visible, a hidden (False) and a legacy NULL project, and asserts only the visible one is named. Fails with the filter removed. - Rename the mock fixture so hidden projects sort before the visible one, killing the "count filtered, names from unfiltered list" mutant. - Add a multi-project case that pins "2 projects:" with a hidden third. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HFUXRa2hBVnK4hXzY8dK68 --- website/tests/test_bio_utils.py | 83 +++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 9 deletions(-) diff --git a/website/tests/test_bio_utils.py b/website/tests/test_bio_utils.py index 1a3444a8..9aa1a755 100644 --- a/website/tests/test_bio_utils.py +++ b/website/tests/test_bio_utils.py @@ -1,16 +1,21 @@ """ Tests for website.utils.bio_utils.auto_generate_bio and its helpers. -Tests use mocks rather than real Person/Position records so they don't have to -navigate Person.save() side-effects (random image assignment, file I/O); the -unit under test is pure presentation logic. +Most tests use mocks rather than real Person/Position records so they don't +have to navigate Person.save() side-effects (random image assignment, file +I/O); the unit under test is pure presentation logic. MemberBioVisibilityTests +is the exception: a DB-backed regression test that renders the real member page. """ from datetime import date, timedelta from unittest.mock import MagicMock, patch from django.test import SimpleTestCase +from django.urls import reverse +from website.models import Position, Project, ProjectRole +from website.models.position import Title +from website.tests.base import DatabaseTestCase from website.utils.bio_utils import ( _join_with_oxford_comma, auto_generate_bio, @@ -286,10 +291,13 @@ def test_one_project_no_pubs(self): def test_hidden_projects_are_not_named(self): """Hidden (private) projects must not leak into the public bio.""" + # The hidden projects sort BEFORE the visible one, so an implementation + # that filters the count but takes names from the unfiltered sorted + # list would name a hidden project here. projs = [ - _make_project("Public One", "publicone"), - _make_project("Secret", "secret", is_visible=False), - _make_project("Unset", "unset", is_visible=None), + _make_project("Zulu Public", "zulupublic"), + _make_project("Alpha Hidden", "alphahidden", is_visible=False), + _make_project("Bravo Unset", "bravounset", is_visible=None), ] person = _make_person( is_current_member=True, @@ -299,9 +307,28 @@ def test_hidden_projects_are_not_named(self): ) bio = auto_generate_bio(person) self.assertIn("a project called Public One", bio) - self.assertNotIn("Secret", bio) - self.assertNotIn("Unset", bio) + self.assertIn(">Zulu Public", bio) + self.assertNotIn("Alpha Hidden", bio) + self.assertNotIn("Bravo Unset", bio) + + def test_hidden_projects_excluded_from_multi_project_count(self): + """Count and names on the multi-project path ignore hidden projects.""" + projs = [ + _make_project("Alpha Hidden", "alphahidden", is_visible=False), + _make_project("Mike Public", "mikepublic"), + _make_project("Zulu Public", "zulupublic"), + ] + person = _make_person( + is_current_member=True, + is_active=True, + current_title="Undergrad", + projects=projs, + ) + bio = auto_generate_bio(person) + self.assertIn("2 projects:", bio) + self.assertIn(">Mike Public", bio) + self.assertIn(">Zulu Public", bio) + self.assertNotIn("Alpha Hidden", bio) def test_only_hidden_projects_and_no_pubs_has_no_contributions(self): person = _make_person( @@ -560,3 +587,41 @@ def test_returns_years_string_for_long_durations(self): result.endswith(" years"), msg=f"Expected a years string, got {result!r}", ) + + +class MemberBioVisibilityTests(DatabaseTestCase): + """DB-backed regression: the rendered member page never names a hidden project. + + Exercises the real Person.get_projects and the member view, which the + mock-based tests above cannot. Covers the bio, the meta description built + from it, and the projects grid. + """ + + def test_member_page_does_not_name_hidden_projects(self): + person = self.make_person(first_name="Probe", last_name="Person") + Position.objects.create( + person=person, start_date=date(2020, 1, 1), title=Title.PHD_STUDENT + ) + shown = self.make_project(name="Zq Shown", is_visible=True) + hidden = self.make_project(name="Zq Hidden", is_visible=False) + unset = self.make_project(name="Zq Unset", is_visible=True) + # Legacy NULL row: update() bypasses Project.save()'s normalization. + Project.objects.filter(pk=unset.pk).update(is_visible=None) + for proj in (shown, hidden, unset): + ProjectRole.objects.create( + person=person, project=proj, start_date=date(2021, 1, 1) + ) + person.refresh_from_db() + + response = self.client.get( + reverse( + "website:member_by_name", + kwargs={"member_name": person.url_name}, + ) + ) + self.assertEqual(response.status_code, 200) + html = response.content.decode() + self.assertIn("a project called", html) + self.assertIn("Zq Shown", html) + self.assertNotIn("Zq Hidden", html) + self.assertNotIn("Zq Unset", html)