From 43e5391c497391ceae90ae0dd0799dd422ea0302 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 20 Sep 2023 11:30:05 +0200 Subject: [PATCH 1/2] Fix map displayed more than once in user dashboard when multiple editors fix #1325 --- umap/tests/test_views.py | 17 +++++++++++++++++ umap/views.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/umap/tests/test_views.py b/umap/tests/test_views.py index 780cf5ad..e53d2230 100644 --- a/umap/tests/test_views.py +++ b/umap/tests/test_views.py @@ -11,6 +11,8 @@ from django.test import RequestFactory from umap import VERSION from umap.views import validate_url +from .base import UserFactory + User = get_user_model() @@ -283,6 +285,21 @@ def test_user_dashboard_display_user_maps(client, map): assert "Owner only" in body +@pytest.mark.django_db +def test_user_dashboard_display_user_maps_distinct(client, map): + # cf https://github.com/umap-project/umap/issues/1325 + user1 = UserFactory(username='user1') + user2 = UserFactory(username='user2') + map.editors.add(user1) + map.editors.add(user2) + map.save() + client.login(username=map.owner.username, password="123123") + response = client.get(reverse("user_dashboard")) + assert response.status_code == 200 + body = response.content.decode() + assert body.count(map.name) == 1 + + @pytest.mark.django_db def test_logout_should_return_json_in_ajax(client, user, settings): client.login(username=user.username, password="123123") diff --git a/umap/views.py b/umap/views.py index f33296d9..73c98028 100644 --- a/umap/views.py +++ b/umap/views.py @@ -275,7 +275,7 @@ class UserDashboard(PaginatorMixin, DetailView, SearchMixin): def get_maps(self): qs = self.get_search_queryset() or Map.objects.all() - qs = qs.filter(Q(owner=self.object) | Q(editors=self.object)) + qs = qs.filter(owner=self.object).union(qs.filter(editors=self.object)) return qs.order_by("-modified_at") def get_context_data(self, **kwargs): From f6730a9829fed9398362817dc1db9edc94d47666 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 20 Sep 2023 15:17:29 +0200 Subject: [PATCH 2/2] Update umap/views.py Co-authored-by: David Larlet <3556+davidbgk@users.noreply.github.com> --- umap/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/umap/views.py b/umap/views.py index 73c98028..c42a5ead 100644 --- a/umap/views.py +++ b/umap/views.py @@ -275,7 +275,7 @@ class UserDashboard(PaginatorMixin, DetailView, SearchMixin): def get_maps(self): qs = self.get_search_queryset() or Map.objects.all() - qs = qs.filter(owner=self.object).union(qs.filter(editors=self.object)) + qs = qs.union(qs.filter(owner=self.object), qs.filter(editors=self.object)) return qs.order_by("-modified_at") def get_context_data(self, **kwargs):