From fd9b98d443f2ba5b52d4036ba0e01fadd38a0fe7 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 31 Jan 2021 13:38:26 -0800 Subject: [PATCH] Fixes logged out list view --- bookwyrm/templates/lists/list.html | 2 +- bookwyrm/tests/views/test_list.py | 8 ++++++++ bookwyrm/views/list.py | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index ab689b1d..213f9dca 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -48,7 +48,7 @@ {% endif %} - {% if not list.curation == 'closed' or request.user == list.user %} + {% if request.user.is_authenticated and not list.curation == 'closed' or request.user == list.user %}

{% if list.curation == 'open' or request.user == list.user %}Add{% else %}Suggest{% endif %} Books

diff --git a/bookwyrm/tests/views/test_list.py b/bookwyrm/tests/views/test_list.py index 790533d7..c3e76745 100644 --- a/bookwyrm/tests/views/test_list.py +++ b/bookwyrm/tests/views/test_list.py @@ -90,6 +90,14 @@ class ListViews(TestCase): result.render() self.assertEqual(result.status_code, 200) + request.user = self.anonymous_user + with patch('bookwyrm.views.list.is_api_request') as is_api: + is_api.return_value = False + result = view(request, self.list.id) + self.assertIsInstance(result, TemplateResponse) + result.render() + self.assertEqual(result.status_code, 200) + with patch('bookwyrm.views.list.is_api_request') as is_api: is_api.return_value = True result = view(request, self.list.id) diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index 4b7a4de4..9ef2ae3b 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -54,10 +54,11 @@ class List(View): return ActivitypubResponse(book_list.to_activity()) query = request.GET.get('q') - if query: + suggestions = None + if query and request.user.is_authenticated: # search for books suggestions = connector_manager.local_search(query, raw=True) - else: + elif request.user.is_authenticated: # just suggest whatever books are nearby suggestions = request.user.shelfbook_set.filter( ~Q(book__in=book_list.books.all())