wip: show user groups maps in dashboard

This commit is contained in:
Yohan Boniface 2024-08-20 11:30:56 +02:00
parent eccbbda44d
commit a5a68cc922
3 changed files with 21 additions and 2 deletions

View file

@ -9,7 +9,7 @@
<ul> <ul>
{% for group in groups %} {% for group in groups %}
<li> <li>
{{ group }} <a href="{% url 'group_update' group.pk %}">({% trans "Edit" %})</a> <a href="{% url 'group_maps' group.pk %}">{{ group }}</a> <a href="{% url 'group_update' group.pk %}">({% trans "Edit" %})</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>

View file

@ -288,6 +288,20 @@ 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_group_maps(client, map, group, user):
user.groups.add(group)
user.save()
map.group = group
map.save()
client.login(username=user.username, password="123123")
response = client.get(reverse("user_dashboard"))
assert response.status_code == 200
body = response.content.decode()
assert map.name in body
assert map.get_absolute_url() in body
@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

View file

@ -370,7 +370,12 @@ 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(owner=self.object).union(qs.filter(editors=self.object)) groups = self.object.groups.all()
qs = (
qs.filter(owner=self.object)
.union(qs.filter(editors=self.object))
.union(qs.filter(group__in=groups))
)
return qs.order_by("-modified_at") return qs.order_by("-modified_at")
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):