forked from Alex/Pterodactyl-Panel
Clean up setting allocation front-end
This commit is contained in:
parent
b41e7ecf09
commit
a1c6aa6358
@ -183,6 +183,12 @@ class AjaxController extends Controller
|
|||||||
$server = Server::getByUUID($uuid);
|
$server = Server::getByUUID($uuid);
|
||||||
$this->authorize('set-connection', $server);
|
$this->authorize('set-connection', $server);
|
||||||
|
|
||||||
|
if ($request->input('connection') === $server->ip . ':' . $server->port) {
|
||||||
|
return response()->json([
|
||||||
|
'error' => 'You are already using this as your default connection.'
|
||||||
|
], 409);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$repo = new Repositories\ServerRepository;
|
$repo = new Repositories\ServerRepository;
|
||||||
|
@ -221,6 +221,13 @@ class ServerPolicy
|
|||||||
return $user->permissions()->server($server)->permission('view-manage')->exists();
|
return $user->permissions()->server($server)->permission('view-manage')->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if user has permission to view allocations for a server.
|
||||||
|
*
|
||||||
|
* @param Pterodactyl\Models\User $user
|
||||||
|
* @param Pterodactyl\Models\Server $server
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public function viewAllocation(User $user, Server $server)
|
public function viewAllocation(User $user, Server $server)
|
||||||
{
|
{
|
||||||
if ($this->isOwner($user, $server)) {
|
if ($this->isOwner($user, $server)) {
|
||||||
@ -230,4 +237,20 @@ class ServerPolicy
|
|||||||
return $user->permissions()->server($server)->permission('view-allocation')->exists();
|
return $user->permissions()->server($server)->permission('view-allocation')->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if user has permission to set the default connection for a server.
|
||||||
|
*
|
||||||
|
* @param Pterodactyl\Models\User $user
|
||||||
|
* @param Pterodactyl\Models\Server $server
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function setAllocation(User $user, Server $server)
|
||||||
|
{
|
||||||
|
if ($this->isOwner($user, $server)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user->permissions()->server($server)->permission('set-allocation')->exists();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -384,7 +384,7 @@ $(window).load(function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@can('view-allocation', $server)
|
@can('set-allocation', $server)
|
||||||
// Send Request
|
// Send Request
|
||||||
$('[data-action="set-connection"]').click(function (event) {
|
$('[data-action="set-connection"]').click(function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -403,16 +403,26 @@ $(window).load(function () {
|
|||||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||||
}
|
}
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
|
swal({
|
||||||
|
type: 'success',
|
||||||
|
title: '',
|
||||||
|
text: data
|
||||||
|
});
|
||||||
$('#conn_options').find('li.active').removeClass('active');
|
$('#conn_options').find('li.active').removeClass('active');
|
||||||
element.parent().addClass('active');
|
element.parent().addClass('active');
|
||||||
alert(data);
|
|
||||||
}).fail(function (jqXHR) {
|
}).fail(function (jqXHR) {
|
||||||
console.error(jqXHR);
|
console.error(jqXHR);
|
||||||
|
var respError;
|
||||||
if (typeof jqXHR.responseJSON.error === 'undefined' || jqXHR.responseJSON.error === '') {
|
if (typeof jqXHR.responseJSON.error === 'undefined' || jqXHR.responseJSON.error === '') {
|
||||||
return alert('An error occured while attempting to perform this action.');
|
respError = 'An error occured while attempting to perform this action.';
|
||||||
} else {
|
} else {
|
||||||
return alert(jqXHR.responseJSON.error);
|
respError = jqXHR.responseJSON.error;
|
||||||
}
|
}
|
||||||
|
swal({
|
||||||
|
type: 'error',
|
||||||
|
title: 'Whoops!',
|
||||||
|
text: respError
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@endcan
|
@endcan
|
||||||
|
Loading…
Reference in New Issue
Block a user