From a411d9a8002efb74f45eab09c9709a701651ab64 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Fri, 18 Nov 2016 17:54:49 +1300 Subject: [PATCH] Disallowing playlist editing where not owned --- src/js/views/Playlist.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/js/views/Playlist.js b/src/js/views/Playlist.js index 5c8e9000..215472e7 100755 --- a/src/js/views/Playlist.js +++ b/src/js/views/Playlist.js @@ -75,13 +75,30 @@ class Playlist extends React.Component{ } reorderTracks( indexes, index ){ - this.props.uiActions.reorderPlaylistTracks( this.props.playlist.uri, indexes, index, this.props.playlist.snapshot_id ) + if( this.isEditable() ){ + this.props.uiActions.reorderPlaylistTracks( this.props.playlist.uri, indexes, index, this.props.playlist.snapshot_id ) + }else{ + alert('Cannot edit a playlist you don\'t own') + } } removeTracks( tracks_indexes ){ this.props.uiActions.removeTracksFromPlaylist( this.props.playlist.uri, tracks_indexes ) } + isEditable(){ + if( helpers.uriSource( this.props.params.uri ) == 'spotify' ){ + if( !this.props.spotify_authorized ) return false + + return ( this.props.playlist && + this.props.playlist.owner && + this.props.playlist.owner.id == this.props.spotify_userid + ) + }else{ + return true + } + } + renderExtraButtons(){ switch( helpers.uriSource( this.props.params.uri ) ){ @@ -94,8 +111,7 @@ class Playlist extends React.Component{ ) case 'spotify': - if( !this.props.spotify_authorized ) return null - if( this.props.playlist.owner && this.props.playlist.owner.id == this.props.spotify_userid ){ + if( this.isEditable() ){ return ( @@ -141,7 +157,7 @@ class Playlist extends React.Component{
- { this.props.playlist.tracks ? this.removeTracks(tracks_indexes) } reorderTracks={ (indexes, index) => this.reorderTracks(indexes, index) } /> : null } + { this.props.playlist.tracks ? this.removeTracks(tracks_indexes) } reorderTracks={ (indexes, index) => this.reorderTracks(indexes, index) } /> : null } this.loadMore() }/>