diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 3ee791fe..6e12222d 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -34,4 +34,9 @@ class AdminController extends Controller { return View::make('shared.null'); } + + public function getTracks() + { + return View::make('shared.null'); + } } diff --git a/app/Http/Controllers/Api/Web/TracksController.php b/app/Http/Controllers/Api/Web/TracksController.php index 29ac29ff..7cbe9d70 100644 --- a/app/Http/Controllers/Api/Web/TracksController.php +++ b/app/Http/Controllers/Api/Web/TracksController.php @@ -128,7 +128,7 @@ class TracksController extends ApiControllerBase return Response::json(['url' => $url], 200); } - public function getIndex() + public function getIndex($all = false) { $page = 1; $perPage = 45; @@ -137,12 +137,22 @@ class TracksController extends ApiControllerBase $page = Input::get('page'); } - $query = Track::summary() - ->userDetails() - ->listed() - ->explicitFilter() - ->published() - ->with('user', 'genre', 'cover', 'album', 'album.user'); + $query = null; + + if ($all) { + $query = Track::summary() + ->userDetails() + ->listed() + ->explicitFilter() + ->with('user', 'genre', 'cover', 'album', 'album.user'); + } else { + $query = Track::summary() + ->userDetails() + ->listed() + ->explicitFilter() + ->published() + ->with('user', 'genre', 'cover', 'album', 'album.user'); + } $this->applyFilters($query); @@ -164,6 +174,12 @@ class TracksController extends ApiControllerBase ], 200); } + public function getAllTracks() + { + $this->authorize('access-admin-area'); + return $this->getIndex(true); + } + public function getOwned() { $query = Track::summary()->where('user_id', \Auth::user()->id)->orderBy('created_at', 'desc'); diff --git a/app/Http/routes.php b/app/Http/routes.php index 52cd0cf2..62dceb63 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -156,6 +156,8 @@ Route::group(['prefix' => 'api/web'], function() { Route::post('/genres', 'Api\Web\GenresController@postCreate'); Route::put('/genres/{id}', 'Api\Web\GenresController@putRename')->where('id', '\d+'); Route::delete('/genres/{id}', 'Api\Web\GenresController@deleteGenre')->where('id', '\d+'); + + Route::get('/tracks', 'Api\Web\TracksController@getAllTracks'); }); Route::post('/auth/logout', 'Api\Web\AuthController@postLogout'); @@ -164,6 +166,7 @@ Route::group(['prefix' => 'api/web'], function() { Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'can:access-admin-area']], function() { Route::get('/genres', 'AdminController@getGenres'); + Route::get('/tracks', 'AdminController@getTracks'); Route::get('/', 'AdminController@getIndex'); }); diff --git a/app/Models/Track.php b/app/Models/Track.php index cbfd510d..9d05cb9e 100644 --- a/app/Models/Track.php +++ b/app/Models/Track.php @@ -556,7 +556,7 @@ class Track extends Model implements Searchable public function canView($user) { - if ($this->isPublished()) { + if ($this->isPublished() || $user->hasRole('admin')) { return true; } diff --git a/public/templates/admin/_layout.html b/public/templates/admin/_layout.html index 75f5dfa4..bf04aabd 100644 --- a/public/templates/admin/_layout.html +++ b/public/templates/admin/_layout.html @@ -1,4 +1,5 @@
diff --git a/public/templates/admin/tracks.html b/public/templates/admin/tracks.html new file mode 100644 index 00000000..6f12f17a --- /dev/null +++ b/public/templates/admin/tracks.html @@ -0,0 +1,3 @@ +