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

This commit is contained in:
Eliot Berriot 2020-03-23 12:54:58 +01:00
parent 9e68aea781
commit 7aa299e5b4
No known key found for this signature in database
GPG Key ID: 6B501DFD73514E14
2 changed files with 7 additions and 3 deletions

View File

@ -33,8 +33,12 @@ def library_track(request, pk, redirect_to_ap):
except models.Track.DoesNotExist:
return []
playable_uploads = obj.uploads.playable_by(None).order_by("id")
upload = playable_uploads.first()
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(
settings.FUNKWHALE_URL,
@ -84,8 +88,6 @@ def library_track(request, pk, redirect_to_ap):
"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:
metas.append(
{

View File

@ -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.Track", {}, "library_track", "pk", "pk",),
("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(