From 8a38dd63c9ee4a77b03509211d4e9b7b5b5780b2 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 17 Dec 2024 10:37:07 +0100 Subject: [PATCH] fix: show private/draft maps in team maps for members --- umap/tests/test_team_views.py | 9 ++++++--- umap/views.py | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/umap/tests/test_team_views.py b/umap/tests/test_team_views.py index 29928056..3b3e3a6e 100644 --- a/umap/tests/test_team_views.py +++ b/umap/tests/test_team_views.py @@ -15,9 +15,12 @@ def test_can_see_team_maps(client, map, team): assert map.name in response.content.decode() -def test_others_cannot_see_team_private_maps_in_team_page(client, map, team, user): +@pytest.mark.parametrize("share_status", [Map.PRIVATE, Map.DRAFT]) +def test_others_cannot_see_team_private_maps_in_team_page( + client, map, team, user, share_status +): map.team = team - map.share_status = Map.PRIVATE + map.share_status = share_status map.save() url = reverse("team_maps", args=(team.pk,)) response = client.get(url) @@ -43,7 +46,7 @@ def test_members_can_see_private_maps_in_team_page( client.login(username=user.username, password="123123") response = client.get(url) assert response.status_code == 200 - assert map.name not in response.content.decode() + assert map.name in response.content.decode() def test_user_can_see_their_teams(client, team, user): diff --git a/umap/views.py b/umap/views.py index 895fe3b1..08de5a7a 100644 --- a/umap/views.py +++ b/umap/views.py @@ -317,7 +317,11 @@ class TeamMaps(PaginatorMixin, DetailView): context_object_name = "current_team" def get_maps(self): - return Map.public.filter(team=self.object).order_by("-modified_at") + qs = Map.public + user = self.request.user + if user.is_authenticated and user in self.object.users.all(): + qs = Map.objects + return qs.filter(team=self.object).order_by("-modified_at") def get_context_data(self, **kwargs): kwargs.update(