Fix anonymous maps displayed by mistake in user dashboard
This commit is contained in:
parent
f11ef754c4
commit
27f3e08bc1
2 changed files with 4 additions and 2 deletions
|
@ -11,7 +11,7 @@ from django.test import RequestFactory
|
||||||
from umap import VERSION
|
from umap import VERSION
|
||||||
from umap.views import validate_url
|
from umap.views import validate_url
|
||||||
|
|
||||||
from .base import UserFactory
|
from .base import UserFactory, MapFactory
|
||||||
|
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
|
||||||
|
@ -288,6 +288,7 @@ def test_user_dashboard_display_user_maps(client, map):
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_user_dashboard_display_user_maps_distinct(client, map):
|
def test_user_dashboard_display_user_maps_distinct(client, map):
|
||||||
# cf https://github.com/umap-project/umap/issues/1325
|
# cf https://github.com/umap-project/umap/issues/1325
|
||||||
|
anonymap = MapFactory(name="Map witout owner should not appear")
|
||||||
user1 = UserFactory(username='user1')
|
user1 = UserFactory(username='user1')
|
||||||
user2 = UserFactory(username='user2')
|
user2 = UserFactory(username='user2')
|
||||||
map.editors.add(user1)
|
map.editors.add(user1)
|
||||||
|
@ -298,6 +299,7 @@ def test_user_dashboard_display_user_maps_distinct(client, map):
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
body = response.content.decode()
|
body = response.content.decode()
|
||||||
assert body.count(map.name) == 1
|
assert body.count(map.name) == 1
|
||||||
|
assert body.count(anonymap.name) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
|
|
@ -277,7 +277,7 @@ class UserDashboard(PaginatorMixin, DetailView, SearchMixin):
|
||||||
|
|
||||||
def get_maps(self):
|
def get_maps(self):
|
||||||
qs = self.get_search_queryset() or Map.objects.all()
|
qs = self.get_search_queryset() or Map.objects.all()
|
||||||
qs = qs.union(qs.filter(owner=self.object), qs.filter(editors=self.object))
|
qs = qs.filter(owner=self.object).union(qs.filter(editors=self.object))
|
||||||
return qs.order_by("-modified_at")
|
return qs.order_by("-modified_at")
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue