From 8c04acd8e7b99c293c197efbdef232eada4a6cc9 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Thu, 2 May 2019 10:17:55 +0200 Subject: [PATCH] Fix #812: Ensure correct track duration and playable status when browsing radios --- api/funkwhale_api/radios/views.py | 9 +++++++-- changes/changelog.d/812.bugfix | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changes/changelog.d/812.bugfix diff --git a/api/funkwhale_api/radios/views.py b/api/funkwhale_api/radios/views.py index 0a5f1cd6c..3c8f41c91 100644 --- a/api/funkwhale_api/radios/views.py +++ b/api/funkwhale_api/radios/views.py @@ -5,6 +5,7 @@ from rest_framework.response import Response from funkwhale_api.common import permissions as common_permissions from funkwhale_api.music.serializers import TrackSerializer +from funkwhale_api.music import utils as music_utils from funkwhale_api.users.oauth import permissions as oauth_permissions from . import filters, filtersets, models, serializers @@ -47,7 +48,9 @@ class RadioViewSet( def tracks(self, request, *args, **kwargs): radio = self.get_object() tracks = radio.get_candidates().for_nested_serialization() - + actor = music_utils.get_actor_from_request(self.request) + tracks = tracks.with_playable_uploads(actor) + tracks = tracks.playable_by(actor) page = self.paginate_queryset(tracks) if page is not None: serializer = TrackSerializer(page, many=True) @@ -110,7 +113,9 @@ class RadioSessionViewSet( def get_serializer_context(self): context = super().get_serializer_context() - context["user"] = self.request.user + context["user"] = ( + self.request.user if self.request.user.is_authenticated else None + ) return context diff --git a/changes/changelog.d/812.bugfix b/changes/changelog.d/812.bugfix new file mode 100644 index 000000000..ec604dcec --- /dev/null +++ b/changes/changelog.d/812.bugfix @@ -0,0 +1 @@ +Ensure correct track duration and playable status when browsing radios (#812)