Resolve "Adding track to playlist over Subsonic API will duplicate playlist"

This commit is contained in:
Marcos Peña 2022-06-17 06:39:09 +00:00 committed by Georg Krause
parent 93708671dc
commit c3207c82d5
3 changed files with 39 additions and 4 deletions

View File

@ -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:

View File

@ -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")

View File

@ -0,0 +1 @@
Fixes subsonic createPlaylist's endpoint doesn't update playlist (#1263) (1263)