1
0
Fork 1
mirror of https://github.com/bookwyrm-social/bookwyrm.git synced 2025-04-24 03:04:10 +00:00

Merge pull request from timothyjrogers/anonymous-view-for-lists-on-profile

Removed login_required from viewing public lists from user profiles
This commit is contained in:
Hugh Rundle 2025-03-24 14:00:38 +11:00 committed by GitHub
commit 9f0838d260
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions
bookwyrm
tests/views/lists
views/list

View file

@ -145,11 +145,21 @@ class ListViews(TestCase):
def test_user_lists_page_logged_out(self):
"""there are so many views, this just makes sure it LOADS"""
view = views.UserLists.as_view()
with (
patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"),
patch("bookwyrm.lists_stream.remove_list_task.delay"),
):
models.List.objects.create(name="Public list", user=self.local_user)
models.List.objects.create(
name="Private list", privacy="direct", user=self.local_user
)
request = self.factory.get("")
request.user = self.anonymous_user
result = view(request, self.local_user.username)
self.assertEqual(result.status_code, 302)
self.assertIsInstance(result, TemplateResponse)
validate_html(result.render())
self.assertEqual(result.status_code, 200)
def test_lists_create(self):
"""create list view"""

View file

@ -10,6 +10,9 @@ from bookwyrm import forms, models
from bookwyrm.lists_stream import ListsStream
from bookwyrm.views.helpers import get_user_from_username
import logging
logger = logging.getLogger(__name__)
# pylint: disable=no-self-use
class Lists(View):
@ -64,12 +67,12 @@ class SavedLists(View):
return TemplateResponse(request, "lists/lists.html", data)
@method_decorator(login_required, name="dispatch")
class UserLists(View):
"""a user's book list page"""
def get(self, request, username):
"""display a book list"""
user = get_user_from_username(request.user, username)
lists = models.List.privacy_filter(request.user).filter(user=user)
paginated = Paginator(lists, 12)