[media] Allow anonymous users to view media detail pages
This commit is contained in:
@ -4,6 +4,7 @@ from unittest.mock import MagicMock, patch
|
||||
import pytest
|
||||
import time_machine
|
||||
from agents.models import AgentSession
|
||||
from books.models import Book
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
@ -1225,6 +1226,24 @@ def test_scrobble_start_with_video_uuid_creates_scrobble(client, valid_auth_toke
|
||||
assert Scrobble.objects.filter(video=video, user=user).exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_long_play_media_detail_view_works_for_anonymous_user(client):
|
||||
book = Book.objects.create(title="Anonymous Accessible Book")
|
||||
url = reverse("books:book_detail", kwargs={"slug": book.uuid})
|
||||
response = client.get(url)
|
||||
assert response.status_code == 200
|
||||
assert "Anonymous Accessible Book" in response.content.decode()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_short_play_media_detail_view_works_for_anonymous_user(client):
|
||||
video = Video.objects.create(title="Anonymous Accessible Video")
|
||||
url = reverse("videos:video_detail", kwargs={"slug": video.uuid})
|
||||
response = client.get(url)
|
||||
assert response.status_code == 200
|
||||
assert "Anonymous Accessible Video" in response.content.decode()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_long_plays_view_does_not_crash_on_unknown_app_labels(client):
|
||||
user = get_user_model().objects.create_user(
|
||||
|
||||
@ -215,7 +215,11 @@ class ScrobbleableDetailView(ChartContextMixin, DetailView):
|
||||
context_data["is_paginated"] = paginator.num_pages > 1
|
||||
|
||||
media = self.object
|
||||
if hasattr(media, "is_long_play_media") and media.is_long_play_media():
|
||||
if (
|
||||
not self.request.user.is_anonymous
|
||||
and hasattr(media, "is_long_play_media")
|
||||
and media.is_long_play_media()
|
||||
):
|
||||
qs = media.scrobble_set.filter(user=self.request.user)
|
||||
completed = (
|
||||
qs.filter(long_play_complete=True).order_by("-timestamp").first()
|
||||
|
||||
Reference in New Issue
Block a user