Skip to content

Commit

Permalink
feat(handlers/playlist): allow playlist sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
nadiamoe committed Jul 3, 2024
1 parent 37fbd85 commit 6c21c0a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions server/ctrlsubsonic/handlers_playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *Controller) ServeGetPlaylists(r *http.Request) *spec.Response {
if err != nil {
return spec.NewError(0, "error reading playlist %q: %v", path, err)
}
if playlist.UserID != user.ID && !playlist.IsPublic {
if !playlist.CanRead(user.ID) {
continue
}
playlistID := playlistIDEncode(path)
Expand Down Expand Up @@ -82,7 +82,7 @@ func (c *Controller) ServeCreateOrUpdatePlaylist(r *http.Request) *spec.Response
}
}

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

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

// update meta info
if playlist.UserID != 0 && playlist.UserID != user.ID {
if !playlist.CanWrite(user.ID) {
return spec.NewResponse()
}

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

func (c *Controller) ServeDeletePlaylist(r *http.Request) *spec.Response {
user := r.Context().Value(CtxUser).(*db.User)
params := r.Context().Value(CtxParams).(params.Params)

playlistID := params.GetFirstOr( /* default */ "", "id", "playlistId")
if err := c.playlistStore.Delete(playlistIDDecode(playlistID)); err != nil {
playlistPath := playlistIDDecode(playlistID)
playlist, err := c.playlistStore.Read(playlistPath)
if err != nil {
return spec.NewError(0, "find playlist: %v", err)
}

if !playlist.CanDelete(user.ID) {
return spec.NewError(0, "you cannot delete playlists you do not own")
}

if err := c.playlistStore.Delete(playlistPath); err != nil {
return spec.NewError(0, "delete playlist: %v", err)
}
return spec.NewResponse()
Expand Down

0 comments on commit 6c21c0a

Please sign in to comment.