Block regular users from changing their own playlists ownership
This commit is contained in:
@@ -399,15 +399,22 @@ func (r *playlistRepository) Save(entity interface{}) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *playlistRepository) Update(id string, entity interface{}, cols ...string) error {
|
func (r *playlistRepository) Update(id string, entity interface{}, cols ...string) error {
|
||||||
|
pls := dbPlaylist{Playlist: *entity.(*model.Playlist)}
|
||||||
current, err := r.Get(id)
|
current, err := r.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
usr := loggedUser(r.ctx)
|
usr := loggedUser(r.ctx)
|
||||||
if !usr.IsAdmin && current.OwnerID != usr.ID {
|
if !usr.IsAdmin {
|
||||||
return rest.ErrPermissionDenied
|
// Only the owner can update the playlist
|
||||||
|
if current.OwnerID != usr.ID {
|
||||||
|
return rest.ErrPermissionDenied
|
||||||
|
}
|
||||||
|
// Regular users can't change the ownership of a playlist
|
||||||
|
if pls.OwnerID != "" && pls.OwnerID != usr.ID {
|
||||||
|
return rest.ErrPermissionDenied
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pls := dbPlaylist{Playlist: *entity.(*model.Playlist)}
|
|
||||||
pls.ID = id
|
pls.ID = id
|
||||||
pls.UpdatedAt = time.Now()
|
pls.UpdatedAt = time.Now()
|
||||||
_, err = r.put(id, pls, append(cols, "updatedAt")...)
|
_, err = r.put(id, pls, append(cols, "updatedAt")...)
|
||||||
|
|||||||
Reference in New Issue
Block a user