From c87712c995de998e62b1725f224ba47c37d4537a Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 27 Sep 2021 18:41:29 +1000 Subject: [PATCH] allow group members to add items to group lists directly NOTE: this will be the case regardless of privacy settings of the list --- bookwyrm/templates/lists/list.html | 4 ++-- bookwyrm/views/list.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index 35014a7b..ea28bb77 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -123,7 +123,7 @@ {% if request.user.is_authenticated and not list.curation == 'closed' or request.user == list.user %}

- {% if list.curation == 'open' or request.user == list.user %} + {% if list.curation == 'open' or request.user == list.user or is_group_member %} {% trans "Add Books" %} {% else %} {% trans "Suggest Books" %} @@ -176,7 +176,7 @@ {% csrf_token %} - + diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index fb224cdf..912c3cfd 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -177,6 +177,7 @@ class List(View): ][: 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,7 +192,8 @@ class List(View): "sort_form": forms.SortListForm( {"direction": direction, "sort_by": sort_by} ), - "user_groups": user_groups + "user_groups": user_groups, + "is_group_member": is_group_member } return TemplateResponse(request, "lists/list.html", data) @@ -292,13 +294,17 @@ def delete_list(request, list_id): def add_book(request): """put a book on a list""" 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 if not book_list.visible_to_user(request.user): return HttpResponseNotFound() book = get_object_or_404(models.Edition, id=request.POST.get("book")) # do you have permission to add to the list? try: - if request.user == book_list.user or book_list.curation == "open": + if request.user == book_list.user or is_group_member or book_list.curation == "open": # add the book at the latest order of approved books, before pending books order_max = ( book_list.listitem_set.filter(approved=True).aggregate(Max("order"))[