diff --git a/api/funkwhale_api/subsonic/views.py b/api/funkwhale_api/subsonic/views.py index bb576c3ce..8ea2fba5a 100644 --- a/api/funkwhale_api/subsonic/views.py +++ b/api/funkwhale_api/subsonic/views.py @@ -670,17 +670,31 @@ class SubsonicViewSet(viewsets.GenericViewSet): def create_playlist(self, request, *args, **kwargs): data = request.GET or request.POST name = data.get("name", "") - if not name: + createPlaylist = True + playListId = data.get("playlistId", "") + if name and playListId: return response.Response( { "error": { "code": 10, - "message": "Playlist ID or name must be specified.", + "message": "You can only supply either a playlistId or name, not both.", } } ) - - playlist = request.user.playlists.create(name=name) + if playListId: + playlist = request.user.playlists.get(pk=playListId) + createPlaylist = False + if not name and not playlist: + return response.Response( + { + "error": { + "code": 10, + "message": "A valid playlist ID or name must be specified.", + } + } + ) + if createPlaylist: + playlist = request.user.playlists.create(name=name) ids = [] for i in data.getlist("songId"): try: diff --git a/api/tests/subsonic/test_views.py b/api/tests/subsonic/test_views.py index 473120075..ef8bf42be 100644 --- a/api/tests/subsonic/test_views.py +++ b/api/tests/subsonic/test_views.py @@ -708,6 +708,26 @@ def test_create_playlist(f, db, logged_in_api_client, factories): } +@pytest.mark.parametrize("f", ["json"]) +def test_create_playlist_with_update(f, db, logged_in_api_client, factories): + url = reverse("api:subsonic-create_playlist") + assert url.endswith("createPlaylist") is True + playlist = factories["playlists.Playlist"](user=logged_in_api_client.user) + factories["playlists.PlaylistTrack"](index=0, playlist=playlist) + track1 = factories["music.Track"]() + track2 = factories["music.Track"]() + response = logged_in_api_client.get( + url, {"f": f, "playlistId": playlist.pk, "songId": [track1.pk, track2.pk]} + ) + playlist.refresh_from_db() + assert response.status_code == 200 + assert playlist.playlist_tracks.count() == 3 + qs = playlist.__class__.objects.with_tracks_count() + assert response.data == { + "playlist": serializers.get_playlist_detail_data(qs.first()) + } + + @pytest.mark.parametrize("f", ["json"]) def test_get_music_folders(f, db, logged_in_api_client, factories): url = reverse("api:subsonic-get_music_folders") diff --git a/changes/changelog.d/1263.bugfix b/changes/changelog.d/1263.bugfix new file mode 100644 index 000000000..55d71c9f8 --- /dev/null +++ b/changes/changelog.d/1263.bugfix @@ -0,0 +1 @@ +Fixes subsonic createPlaylist's endpoint doesn't update playlist (#1263) (1263)