Merge pull request #1326 from umap-project/dashboard-duplicate-map
Fix map displayed more than once in user dashboard when multiple editors
This commit is contained in:
commit
99831dc04d
2 changed files with 18 additions and 1 deletions
|
@ -11,6 +11,8 @@ 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
|
||||||
|
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
@ -283,6 +285,21 @@ def test_user_dashboard_display_user_maps(client, map):
|
||||||
assert "Owner only" in body
|
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
|
@pytest.mark.django_db
|
||||||
def test_logout_should_return_json_in_ajax(client, user, settings):
|
def test_logout_should_return_json_in_ajax(client, user, settings):
|
||||||
client.login(username=user.username, password="123123")
|
client.login(username=user.username, password="123123")
|
||||||
|
|
|
@ -275,7 +275,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.filter(Q(owner=self.object) | Q(editors=self.object))
|
qs = qs.union(qs.filter(owner=self.object), 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