Let admins download all items in playlists

This commit is contained in:
Josef Citrine 2016-12-21 02:55:49 +00:00
parent e625c7ddea
commit 25e023ccb7
2 changed files with 5 additions and 4 deletions

View file

@ -63,7 +63,7 @@ class PlaylistsController extends Controller
public function getDownload($id, $extension)
{
$playlist = Playlist::with('tracks', 'tracks.trackFiles', 'user', 'tracks.album')->find($id);
if (!$playlist || (!$playlist->is_public && !Auth::check()) || (!$playlist->is_public && ($playlist->user_id !== Auth::user()->id))) {
if (!$playlist || (!$playlist->is_public && !Auth::check()) || !$playlist->canView(Auth::user()) || (!$playlist->is_public && ($playlist->user_id !== Auth::user()->id))) {
App::abort(404);
}
@ -88,6 +88,6 @@ class PlaylistsController extends Controller
ResourceLogItem::logItem('playlist', $id, ResourceLogItem::DOWNLOAD, $format['index']);
$downloader = new PlaylistDownloader($playlist, $formatName);
$downloader->download();
$downloader->download(Auth::user());
}
}

View file

@ -22,6 +22,7 @@ namespace Poniverse\Ponyfm;
use Poniverse\Ponyfm\Models\Playlist;
use Poniverse\Ponyfm\Models\Track;
use Poniverse\Ponyfm\Models\User;
use ZipStream;
class PlaylistDownloader
@ -42,7 +43,7 @@ class PlaylistDownloader
$this->_format = $format;
}
public function download()
public function download(User $user)
{
// Check whether the format is lossless yet not all master files are lossless
$isLosslessFormatWithLossyTracks = in_array($this->_format, Track::$LosslessFormats)
@ -71,7 +72,7 @@ class PlaylistDownloader
$m3u = '';
$index = 1;
foreach ($this->_playlist->tracks as $track) {
if (!$track->is_downloadable) {
if (!$track->is_downloadable && !$user->hasRole('admin')) {
continue;
}