CC-4095: Media Library -> Playlist: dj user can delete the playlist owned by
others on some situation. - fixed
This commit is contained in:
parent
d90d83200e
commit
39506740eb
3 changed files with 37 additions and 22 deletions
|
@ -802,12 +802,33 @@ class Application_Model_Playlist {
|
|||
* Delete playlists that match the ids..
|
||||
* @param array $p_ids
|
||||
*/
|
||||
public static function DeletePlaylists($p_ids)
|
||||
public static function DeletePlaylists($p_ids, $p_userId)
|
||||
{
|
||||
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
|
||||
$leftOver = self::playlistsNotOwnedByUser($p_ids, $p_userId);
|
||||
if(count($leftOver) == 0){
|
||||
CcPlaylistQuery::create()->findPKs($p_ids)->delete();
|
||||
}else{
|
||||
throw new PlaylistNoPermissionException;
|
||||
}
|
||||
}
|
||||
|
||||
// This function returns that are not owen by $p_user_id among $p_ids
|
||||
private static function playlistsNotOwnedByUser($p_ids, $p_userId){
|
||||
$ownedByUser = CcPlaylistQuery::create()->filterByDbCreatorId($p_userId)->find()->getData();
|
||||
$selectedPls = $p_ids;
|
||||
$ownedPls = array();
|
||||
foreach($ownedByUser as $pl){
|
||||
if( in_array($pl->getDbId(), $selectedPls) ){
|
||||
$ownedPls[] = $pl->getDbId();
|
||||
}
|
||||
}
|
||||
|
||||
$leftOvers = array_diff($selectedPls, $ownedPls);
|
||||
return $leftOvers;
|
||||
}
|
||||
|
||||
} // class Playlist
|
||||
|
||||
class PlaylistNotFoundException extends Exception {}
|
||||
class PlaylistNoPermissionException extends Exception {}
|
||||
class PlaylistOutDatedException extends Exception {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue