Admins can view all tracks

This commit is contained in:
Josef Citrine 2016-05-11 17:41:49 +01:00
parent 3b808a17aa
commit 481a0a6b9f
9 changed files with 85 additions and 8 deletions

View file

@ -34,4 +34,9 @@ class AdminController extends Controller
{
return View::make('shared.null');
}
public function getTracks()
{
return View::make('shared.null');
}
}

View file

@ -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 = 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');

View file

@ -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');
});

View file

@ -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;
}

View file

@ -1,4 +1,5 @@
<ul class="tabs">
<li ng-class="{active: stateIncludes('admin.tracks')}"><a href="/admin/tracks">All Tracks</a></li>
<li ng-class="{active: stateIncludes('admin.genres')}"><a href="/admin/genres">Genres</a></li>
</ul>

View file

@ -0,0 +1,3 @@
<div class="stretch-to-bottom">
<pfm-tracks-list tracks="tracks" class="three-columns"></pfm-tracks-list>
</div>

View file

@ -271,6 +271,11 @@ ponyfm.config [
controller: 'admin-genres'
templateUrl: '/templates/admin/genres.html'
state.state 'admin.tracks',
url: '/tracks'
controller: 'admin-tracks'
templateUrl: '/templates/admin/tracks.html'
# Homepage
if window.pfm.auth.isLogged

View file

@ -0,0 +1,34 @@
# Pony.fm - A community for pony fan music.
# Copyright (C) 2016 Josef Citrine
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
window.pfm.preloaders['admin-tracks'] = [
'tracks', '$state'
(tracks, $state) ->
tracks.loadFilters().then(->
tracks.mainQuery.fromFilterString($state.params.filter)
tracks.mainQuery.setPage $state.params.page || 1
tracks.mainQuery.setAdmin true
tracks.mainQuery.fetch()
)
]
module.exports = angular.module('ponyfm').controller "admin-tracks", [
'$scope', 'tracks', '$state',
($scope, tracks, $state) ->
tracks.mainQuery.fetch().done (searchResults) ->
$scope.tracks = searchResults.tracks
]

View file

@ -23,6 +23,7 @@ module.exports = angular.module('ponyfm').factory('tracks', [
class Query
cachedDef: null
page: 1
admin: false
listeners: []
constructor: (@availableFilters) ->
@ -94,6 +95,10 @@ module.exports = angular.module('ponyfm').factory('tracks', [
@page = page
@cachedDef = null
setAdmin: (value) ->
@cachedDef = null
@admin = value
setFilter: (type, value) ->
@cachedDef = null
@page = 1
@ -145,6 +150,11 @@ module.exports = angular.module('ponyfm').factory('tracks', [
trackDef = @cachedDef
query = '/api/web/tracks?'
if @admin
query = '/api/web/admin/tracks?'
parts = ['page=' + @page]
_.each @availableFilters, (filter, name) =>
if filter.type == 'single'