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())