mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2025-01-31 03:16:42 +01:00
Admin album editing
This commit is contained in:
parent
fb7f291f31
commit
87d25bb8b8
6 changed files with 33 additions and 12 deletions
|
@ -22,7 +22,9 @@ namespace Poniverse\Ponyfm\Commands;
|
|||
|
||||
use Poniverse\Ponyfm\Models\Album;
|
||||
use Poniverse\Ponyfm\Models\Image;
|
||||
use Poniverse\Ponyfm\Models\User;
|
||||
use Auth;
|
||||
use Gate;
|
||||
use DB;
|
||||
use Validator;
|
||||
|
||||
|
@ -48,7 +50,7 @@ class EditAlbumCommand extends CommandBase
|
|||
{
|
||||
$user = Auth::user();
|
||||
|
||||
return $this->_album && $user != null && $this->_album->user_id == $user->id;
|
||||
return $this->_album && $user != null && Gate::allows('edit', $this->_album);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,7 +63,8 @@ class EditAlbumCommand extends CommandBase
|
|||
'title' => 'required|min:3|max:50',
|
||||
'cover' => 'image|mimes:png|min_width:350|min_height:350',
|
||||
'cover_id' => 'exists:images,id',
|
||||
'track_ids' => 'exists:tracks,id'
|
||||
'track_ids' => 'exists:tracks,id',
|
||||
'username' => 'exists:users,username'
|
||||
];
|
||||
|
||||
$validator = Validator::make($this->_input, $rules);
|
||||
|
@ -86,6 +89,14 @@ class EditAlbumCommand extends CommandBase
|
|||
}
|
||||
}
|
||||
|
||||
if (isset($this->_input['username'])) {
|
||||
$newid = User::where('username', $this->_input['username'])->first()->id;
|
||||
|
||||
if ($this->_album->user_id != $newid) {
|
||||
$this->_album->user_id = $newid;
|
||||
}
|
||||
}
|
||||
|
||||
$trackIds = explode(',', $this->_input['track_ids']);
|
||||
$this->_album->syncTrackIds($trackIds);
|
||||
$this->_album->save();
|
||||
|
|
|
@ -29,6 +29,7 @@ use Poniverse\Ponyfm\Http\Controllers\ApiControllerBase;
|
|||
use Poniverse\Ponyfm\Models\Image;
|
||||
use Poniverse\Ponyfm\Models\ResourceLogItem;
|
||||
use Auth;
|
||||
use Gate;
|
||||
use Input;
|
||||
use Poniverse\Ponyfm\Models\User;
|
||||
use Response;
|
||||
|
@ -171,7 +172,7 @@ class AlbumsController extends ApiControllerBase
|
|||
return $this->notFound('Album ' . $id . ' not found!');
|
||||
}
|
||||
|
||||
if ($album->user_id != Auth::user()->id) {
|
||||
if (Gate::denies('edit', Auth::user())) {
|
||||
return $this->notAuthorized();
|
||||
}
|
||||
|
||||
|
@ -187,6 +188,7 @@ class AlbumsController extends ApiControllerBase
|
|||
'id' => $album->id,
|
||||
'title' => $album->title,
|
||||
'user_id' => $album->user_id,
|
||||
'username' => User::whereId($album->user_id)->first()->username,
|
||||
'slug' => $album->slug,
|
||||
'created_at' => $album->created_at,
|
||||
'published_at' => $album->published_at,
|
||||
|
|
|
@ -25,6 +25,7 @@ use Helpers;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Auth;
|
||||
use Gate;
|
||||
use Cache;
|
||||
use Poniverse\Ponyfm\Contracts\Searchable;
|
||||
use Poniverse\Ponyfm\Exceptions\TrackFileNotFoundException;
|
||||
|
@ -217,8 +218,8 @@ class Album extends Model implements Searchable
|
|||
],
|
||||
'user_data' => $userData,
|
||||
'permissions' => [
|
||||
'delete' => Auth::check() && Auth::user()->id == $album->user_id,
|
||||
'edit' => Auth::check() && Auth::user()->id == $album->user_id
|
||||
'delete' => Gate::allows('delete', $album),
|
||||
'edit' => Gate::allows('edit', $album)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
@ -20,6 +20,11 @@
|
|||
<textarea ng-disabled="isSaving" ng-change="touchModel()" placeholder="Description (optional)" id="description" ng-model="album.description"></textarea>
|
||||
<div class="error">{{errors.description}}</div>
|
||||
</div>
|
||||
<div class="form-row" ng-show="isAdmin" ng-class="{'has-error': errors.username != null}">
|
||||
<label for="title" class="strong">User:</label>
|
||||
<input ng-disabled="isSaving" ng-change="touchModel()" placeholder="Username" type="text" id="username" ng-model="album.username" />
|
||||
<div class="error">{{errors.username}}</div>
|
||||
</div>
|
||||
<div class="form-row" ng-class="{'has-error': errors.cover != null}">
|
||||
<label class="strong">Album Cover: </label>
|
||||
<pfm-image-upload set-image="setCover" image="album.cover" user-id="album.user_id"></pfm-image-upload>
|
||||
|
|
|
@ -108,11 +108,11 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row-fluid" ng-show="isAdmin">
|
||||
<div class="span6 form-row" ng-class="{'has-error': errors.username != null}">
|
||||
<label for="title" class="strong">User:</label>
|
||||
<input ng-disabled="isSaving" ng-change="touchModel()" placeholder="Username" type="text" id="username" ng-model="track.username" />
|
||||
<div class="error">{{errors.username}}</div>
|
||||
</div>
|
||||
<div class="span6 form-row" ng-class="{'has-error': errors.username != null}">
|
||||
<label for="title" class="strong">User:</label>
|
||||
<input ng-disabled="isSaving" ng-change="touchModel()" placeholder="Username" type="text" id="username" ng-model="track.username" />
|
||||
<div class="error">{{errors.username}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label class="strong">Choose a License:</label>
|
||||
|
|
|
@ -25,8 +25,8 @@ window.pfm.preloaders['account-albums-edit'] = [
|
|||
]
|
||||
|
||||
module.exports = angular.module('ponyfm').controller "account-albums-edit", [
|
||||
'$scope', '$state', '$dialog', 'account-albums'
|
||||
($scope, $state, $dialog, albums) ->
|
||||
'$scope', '$state', '$dialog', 'account-albums', 'auth'
|
||||
($scope, $state, $dialog, albums, auth) ->
|
||||
$scope.isNew = $state.params.album_id == undefined
|
||||
$scope.data.isEditorOpen = true
|
||||
$scope.errors = {}
|
||||
|
@ -35,6 +35,7 @@ module.exports = angular.module('ponyfm').controller "account-albums-edit", [
|
|||
$scope.isSaving = false
|
||||
$scope.tracks = []
|
||||
$scope.trackIds = {}
|
||||
$scope.isAdmin = auth.data.isAdmin
|
||||
|
||||
$scope.toggleTrack = (track) ->
|
||||
if $scope.trackIds[track.id]
|
||||
|
@ -140,6 +141,7 @@ module.exports = angular.module('ponyfm').controller "account-albums-edit", [
|
|||
$scope.album =
|
||||
id: album.id
|
||||
user_id: album.user_id
|
||||
username: album.username
|
||||
title: album.title
|
||||
description: album.description
|
||||
remove_cover: false
|
||||
|
|
Loading…
Reference in a new issue