Commit 4541846b authored by Agate's avatar Agate 💬

Merge branch '170-track-upload-json' into 'develop'

See #170: ensure fetch works properly on tracks with public upload

See merge request !1062
parents 48681c39 7aa299e5
Pipeline #10036 passed with stages
in 9 minutes and 42 seconds
...@@ -33,8 +33,12 @@ def library_track(request, pk, redirect_to_ap): ...@@ -33,8 +33,12 @@ def library_track(request, pk, redirect_to_ap):
except models.Track.DoesNotExist: except models.Track.DoesNotExist:
return [] return []
playable_uploads = obj.uploads.playable_by(None).order_by("id")
upload = playable_uploads.first()
if redirect_to_ap: if redirect_to_ap:
raise middleware.ApiRedirect(obj.fid) redirect_url = upload.fid if upload else obj.fid
raise middleware.ApiRedirect(redirect_url)
track_url = utils.join_url( track_url = utils.join_url(
settings.FUNKWHALE_URL, settings.FUNKWHALE_URL,
...@@ -84,8 +88,6 @@ def library_track(request, pk, redirect_to_ap): ...@@ -84,8 +88,6 @@ def library_track(request, pk, redirect_to_ap):
"content": obj.album.attachment_cover.download_url_medium_square_crop, "content": obj.album.attachment_cover.download_url_medium_square_crop,
} }
) )
playable_uploads = obj.uploads.playable_by(None).order_by("id")
upload = playable_uploads.first()
if upload: if upload:
metas.append( metas.append(
{ {
......
...@@ -394,6 +394,8 @@ def test_get_request_head_tags_calls_view_with_proper_arg_when_accept_header_set ...@@ -394,6 +394,8 @@ def test_get_request_head_tags_calls_view_with_proper_arg_when_accept_header_set
("music.Album", {}, "library_album", "pk", "pk",), ("music.Album", {}, "library_album", "pk", "pk",),
("music.Track", {}, "library_track", "pk", "pk",), ("music.Track", {}, "library_track", "pk", "pk",),
("music.Library", {}, "library_library", "uuid", "uuid",), ("music.Library", {}, "library_library", "uuid", "uuid",),
# when a track as a public upload, we should redirect to the upload instead
("music.Upload", {"playable": True}, "library_track", "pk", "track.pk"),
], ],
) )
def test_spa_views_raise_api_redirect_when_accept_json_set( def test_spa_views_raise_api_redirect_when_accept_json_set(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment