Fixes logged out list view

This commit is contained in:
Mouse Reeve 2021-01-31 13:38:26 -08:00
parent 5939a72c81
commit fd9b98d443
3 changed files with 12 additions and 3 deletions

View file

@ -48,7 +48,7 @@
{% endif %}
</section>
{% 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 %}
<section class="column is-one-quarter content">
<h2>{% if list.curation == 'open' or request.user == list.user %}Add{% else %}Suggest{% endif %} Books</h2>
<form name="search" action="{% url 'list' list.id %}" method="GET" class="block">

View file

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

View file

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