From 8496f2403258eb13d10894ecfd1d94aa461d3aee Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sat, 2 Oct 2021 18:09:15 +1000 Subject: [PATCH] fix filters for group members to see and edit group lists --- bookwyrm/templates/lists/form.html | 6 +++--- bookwyrm/templates/lists/list.html | 9 +++++---- bookwyrm/views/list.py | 19 ++++--------------- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/bookwyrm/templates/lists/form.html b/bookwyrm/templates/lists/form.html index a98cae94a..492ccf62a 100644 --- a/bookwyrm/templates/lists/form.html +++ b/bookwyrm/templates/lists/form.html @@ -37,14 +37,14 @@ {% trans "Group" %}

{% trans "Group members can add to and remove from this list" %}

- {% if user_groups %} + {% if user.memberships %}
diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index ea28bb77f..b1246b943 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -1,6 +1,7 @@ {% extends 'lists/layout.html' %} {% load i18n %} {% load bookwyrm_tags %} +{% load bookwyrm_group_tags %} {% load markdown %} {% block panel %} @@ -16,7 +17,7 @@
{% if request.GET.updated %}
- {% if list.curation != "open" and request.user != list.user %} + {% if list.curation != "open" and request.user != list.user and not list.group|is_member:request.user %} {% trans "You successfully suggested a book for this list!" %} {% else %} {% trans "You successfully added a book to this list!" %} @@ -66,7 +67,7 @@

{% blocktrans with username=item.user.display_name user_path=item.user.local_path %}Added by {{ username }}{% endblocktrans %}

- {% if list.user == request.user or list.curation == 'open' and item.user == request.user %} + {% if list.user == request.user or list.curation == 'open' and item.user == request.user or list.group|is_member:request.user %} diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index 912c3cfdb..53f39b549 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -45,13 +45,9 @@ class Lists(View): lists = privacy_filter( request.user, lists, privacy_levels=["public", "followers"] ) - - user_groups = models.Group.objects.filter(members=request.user).order_by("-updated_date") - paginated = Paginator(lists, 12) data = { "lists": paginated.get_page(request.GET.get("page")), - "user_groups": user_groups, "list_form": forms.ListForm(), "path": "/list", } @@ -96,14 +92,12 @@ class UserLists(View): user = get_user_from_username(request.user, username) lists = models.List.objects.filter(user=user) lists = privacy_filter(request.user, lists) - user_groups = models.Group.objects.filter(members=request.user).order_by("-updated_date") paginated = Paginator(lists, 12) data = { "user": user, "is_self": request.user.id == user.id, "lists": paginated.get_page(request.GET.get("page")), - "user_groups": user_groups, "list_form": forms.ListForm(), "path": user.local_path + "/lists", } @@ -176,8 +170,6 @@ class List(View): ).order_by("-updated_date") ][: 5 - len(suggestions)] - user_groups = models.Group.objects.filter(members=request.user).order_by("-updated_date") - is_group_member = book_list.group in user_groups page = paginated.get_page(request.GET.get("page")) data = { "list": book_list, @@ -191,9 +183,7 @@ class List(View): "query": query or "", "sort_form": forms.SortListForm( {"direction": direction, "sort_by": sort_by} - ), - "user_groups": user_groups, - "is_group_member": is_group_member + ) } return TemplateResponse(request, "lists/list.html", data) @@ -296,8 +286,7 @@ def add_book(request): book_list = get_object_or_404(models.List, id=request.POST.get("list")) is_group_member = False if book_list.curation == "group": - user_groups = models.Group.objects.filter(members=request.user).order_by("-updated_date") - is_group_member = book_list.group in user_groups + is_group_member = models.GroupMember.objects.filter(group=book_list.group, user=request.user).exists() if not book_list.visible_to_user(request.user): return HttpResponseNotFound() @@ -350,8 +339,8 @@ def remove_book(request, list_id): with transaction.atomic(): book_list = get_object_or_404(models.List, id=list_id) item = get_object_or_404(models.ListItem, id=request.POST.get("item")) - - if not book_list.user == request.user and not item.user == request.user: + is_group_member = models.GroupMember.objects.filter(group=book_list.group, user=request.user).exists() + if not book_list.user == request.user and not item.user == request.user and not is_group_member: return HttpResponseNotFound() deleted_order = item.order