mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-22 04:58:01 +01:00
Admins can view all tracks
This commit is contained in:
parent
3b808a17aa
commit
481a0a6b9f
9 changed files with 85 additions and 8 deletions
|
@ -34,4 +34,9 @@ class AdminController extends Controller
|
||||||
{
|
{
|
||||||
return View::make('shared.null');
|
return View::make('shared.null');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTracks()
|
||||||
|
{
|
||||||
|
return View::make('shared.null');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ class TracksController extends ApiControllerBase
|
||||||
return Response::json(['url' => $url], 200);
|
return Response::json(['url' => $url], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIndex()
|
public function getIndex($all = false)
|
||||||
{
|
{
|
||||||
$page = 1;
|
$page = 1;
|
||||||
$perPage = 45;
|
$perPage = 45;
|
||||||
|
@ -137,12 +137,22 @@ class TracksController extends ApiControllerBase
|
||||||
$page = Input::get('page');
|
$page = Input::get('page');
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = Track::summary()
|
$query = null;
|
||||||
->userDetails()
|
|
||||||
->listed()
|
if ($all) {
|
||||||
->explicitFilter()
|
$query = Track::summary()
|
||||||
->published()
|
->userDetails()
|
||||||
->with('user', 'genre', 'cover', 'album', 'album.user');
|
->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);
|
$this->applyFilters($query);
|
||||||
|
|
||||||
|
@ -164,6 +174,12 @@ class TracksController extends ApiControllerBase
|
||||||
], 200);
|
], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAllTracks()
|
||||||
|
{
|
||||||
|
$this->authorize('access-admin-area');
|
||||||
|
return $this->getIndex(true);
|
||||||
|
}
|
||||||
|
|
||||||
public function getOwned()
|
public function getOwned()
|
||||||
{
|
{
|
||||||
$query = Track::summary()->where('user_id', \Auth::user()->id)->orderBy('created_at', 'desc');
|
$query = Track::summary()->where('user_id', \Auth::user()->id)->orderBy('created_at', 'desc');
|
||||||
|
|
|
@ -156,6 +156,8 @@ Route::group(['prefix' => 'api/web'], function() {
|
||||||
Route::post('/genres', 'Api\Web\GenresController@postCreate');
|
Route::post('/genres', 'Api\Web\GenresController@postCreate');
|
||||||
Route::put('/genres/{id}', 'Api\Web\GenresController@putRename')->where('id', '\d+');
|
Route::put('/genres/{id}', 'Api\Web\GenresController@putRename')->where('id', '\d+');
|
||||||
Route::delete('/genres/{id}', 'Api\Web\GenresController@deleteGenre')->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');
|
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::group(['prefix' => 'admin', 'middleware' => ['auth', 'can:access-admin-area']], function() {
|
||||||
Route::get('/genres', 'AdminController@getGenres');
|
Route::get('/genres', 'AdminController@getGenres');
|
||||||
|
Route::get('/tracks', 'AdminController@getTracks');
|
||||||
Route::get('/', 'AdminController@getIndex');
|
Route::get('/', 'AdminController@getIndex');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -556,7 +556,7 @@ class Track extends Model implements Searchable
|
||||||
|
|
||||||
public function canView($user)
|
public function canView($user)
|
||||||
{
|
{
|
||||||
if ($this->isPublished()) {
|
if ($this->isPublished() || $user->hasRole('admin')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<ul class="tabs">
|
<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>
|
<li ng-class="{active: stateIncludes('admin.genres')}"><a href="/admin/genres">Genres</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
3
public/templates/admin/tracks.html
Normal file
3
public/templates/admin/tracks.html
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<div class="stretch-to-bottom">
|
||||||
|
<pfm-tracks-list tracks="tracks" class="three-columns"></pfm-tracks-list>
|
||||||
|
</div>
|
|
@ -271,6 +271,11 @@ ponyfm.config [
|
||||||
controller: 'admin-genres'
|
controller: 'admin-genres'
|
||||||
templateUrl: '/templates/admin/genres.html'
|
templateUrl: '/templates/admin/genres.html'
|
||||||
|
|
||||||
|
state.state 'admin.tracks',
|
||||||
|
url: '/tracks'
|
||||||
|
controller: 'admin-tracks'
|
||||||
|
templateUrl: '/templates/admin/tracks.html'
|
||||||
|
|
||||||
# Homepage
|
# Homepage
|
||||||
|
|
||||||
if window.pfm.auth.isLogged
|
if window.pfm.auth.isLogged
|
||||||
|
|
34
resources/assets/scripts/app/controllers/admin-tracks.coffee
Normal file
34
resources/assets/scripts/app/controllers/admin-tracks.coffee
Normal 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
|
||||||
|
]
|
|
@ -23,6 +23,7 @@ module.exports = angular.module('ponyfm').factory('tracks', [
|
||||||
class Query
|
class Query
|
||||||
cachedDef: null
|
cachedDef: null
|
||||||
page: 1
|
page: 1
|
||||||
|
admin: false
|
||||||
listeners: []
|
listeners: []
|
||||||
|
|
||||||
constructor: (@availableFilters) ->
|
constructor: (@availableFilters) ->
|
||||||
|
@ -94,6 +95,10 @@ module.exports = angular.module('ponyfm').factory('tracks', [
|
||||||
@page = page
|
@page = page
|
||||||
@cachedDef = null
|
@cachedDef = null
|
||||||
|
|
||||||
|
setAdmin: (value) ->
|
||||||
|
@cachedDef = null
|
||||||
|
@admin = value
|
||||||
|
|
||||||
setFilter: (type, value) ->
|
setFilter: (type, value) ->
|
||||||
@cachedDef = null
|
@cachedDef = null
|
||||||
@page = 1
|
@page = 1
|
||||||
|
@ -145,6 +150,11 @@ module.exports = angular.module('ponyfm').factory('tracks', [
|
||||||
trackDef = @cachedDef
|
trackDef = @cachedDef
|
||||||
|
|
||||||
query = '/api/web/tracks?'
|
query = '/api/web/tracks?'
|
||||||
|
|
||||||
|
if @admin
|
||||||
|
query = '/api/web/admin/tracks?'
|
||||||
|
|
||||||
|
|
||||||
parts = ['page=' + @page]
|
parts = ['page=' + @page]
|
||||||
_.each @availableFilters, (filter, name) =>
|
_.each @availableFilters, (filter, name) =>
|
||||||
if filter.type == 'single'
|
if filter.type == 'single'
|
||||||
|
|
Loading…
Reference in a new issue