Skip to content

Commit a26e3a9

Browse files
committed
feat(handlers/playlist): allow playlist sharing
1 parent 58737e7 commit a26e3a9

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

server/ctrlsubsonic/handlers_playlist.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (c *Controller) ServeGetPlaylists(r *http.Request) *spec.Response {
3535
if err != nil {
3636
return spec.NewError(0, "error reading playlist %q: %v", path, err)
3737
}
38-
if playlist.UserID != user.ID && !playlist.IsPublic {
38+
if !playlist.CanRead(user.ID) {
3939
continue
4040
}
4141
playlistID := playlistIDEncode(path)
@@ -82,7 +82,7 @@ func (c *Controller) ServeCreateOrUpdatePlaylist(r *http.Request) *spec.Response
8282
}
8383
}
8484

85-
if playlist.UserID != 0 && playlist.UserID != user.ID {
85+
if playlist.UserID != 0 && !playlist.CanWrite(user.ID) {
8686
return spec.NewError(50, "you aren't allowed update that user's playlist")
8787
}
8888

@@ -133,7 +133,7 @@ func (c *Controller) ServeUpdatePlaylist(r *http.Request) *spec.Response {
133133
}
134134

135135
// update meta info
136-
if playlist.UserID != 0 && playlist.UserID != user.ID {
136+
if !playlist.CanWrite(user.ID) {
137137
return spec.NewResponse()
138138
}
139139

@@ -173,9 +173,21 @@ func (c *Controller) ServeUpdatePlaylist(r *http.Request) *spec.Response {
173173
}
174174

175175
func (c *Controller) ServeDeletePlaylist(r *http.Request) *spec.Response {
176+
user := r.Context().Value(CtxUser).(*db.User)
176177
params := r.Context().Value(CtxParams).(params.Params)
178+
177179
playlistID := params.GetFirstOr( /* default */ "", "id", "playlistId")
178-
if err := c.playlistStore.Delete(playlistIDDecode(playlistID)); err != nil {
180+
playlistPath := playlistIDDecode(playlistID)
181+
playlist, err := c.playlistStore.Read(playlistPath)
182+
if err != nil {
183+
return spec.NewError(0, "find playlist: %v", err)
184+
}
185+
186+
if !playlist.CanDelete(user.ID) {
187+
return spec.NewError(0, "you cannot delete playlists you do not own")
188+
}
189+
190+
if err := c.playlistStore.Delete(playlistPath); err != nil {
179191
return spec.NewError(0, "delete playlist: %v", err)
180192
}
181193
return spec.NewResponse()

0 commit comments

Comments
 (0)