Show admin dropdown for admin-access ability (#515)

* Show admin dropdown for admin-access ability closes #509

* Formatting
This commit is contained in:
Nabeel S
2020-01-30 09:00:41 -05:00
committed by GitHub
parent e431f75ad4
commit ff913e5304
8 changed files with 251 additions and 235 deletions
+2 -2
View File
@@ -22,8 +22,8 @@ users:
- id: 2 - id: 2
pilot_id: 2 pilot_id: 2
name: Test User name: Test User
email: test@phpvms.net email: user@phpvms.net
password: test password: user
api_key: testuserapikey api_key: testuserapikey
airline_id: 1 airline_id: 1
rank_id: 1 rank_id: 1
+1 -1
View File
@@ -1,7 +1,7 @@
# All of the different permissions that can be assigned to roles # All of the different permissions that can be assigned to roles
--- ---
- name: admin-access - name: admin-access
display_name: Administrator display_name: Admin Panel
description: Access the admin panel description: Access the admin panel
- name: airlines - name: airlines
display_name: Airlines display_name: Airlines
+48 -32
View File
@@ -30,8 +30,8 @@ class Handler extends ExceptionHandler
* A list of the exception types that should not be reported. * A list of the exception types that should not be reported.
*/ */
protected $dontReport = [ protected $dontReport = [
AuthenticationException::class, //AuthenticationException::class,
AuthorizationException::class, //AuthorizationException::class,
AbstractHttpException::class, AbstractHttpException::class,
IlluminateValidationException::class, IlluminateValidationException::class,
ModelNotFoundException::class, ModelNotFoundException::class,
@@ -50,36 +50,7 @@ class Handler extends ExceptionHandler
public function render($request, Exception $exception) public function render($request, Exception $exception)
{ {
if ($request->is('api/*')) { if ($request->is('api/*')) {
Log::error('API Error', $exception->getTrace()); return $this->handleApiError($request, $exception);
if ($exception instanceof AbstractHttpException) {
return $exception->getResponse();
}
/*
* Not of the HttpException abstract class. Map these into
*/
if ($exception instanceof ModelNotFoundException ||
$exception instanceof NotFoundHttpException) {
$error = new AssetNotFound($exception);
return $error->getResponse();
}
// Custom exceptions should be extending HttpException
if ($exception instanceof SymfonyHttpException) {
$error = new SymfonyException($exception);
return $error->getResponse();
}
// Create the detailed errors from the validation errors
if ($exception instanceof IlluminateValidationException) {
$error = new ValidationException($exception);
return $error->getResponse();
}
$error = new GenericExceptionAbstract($exception);
return $error->getResponse();
} }
if ($exception instanceof AbstractHttpException if ($exception instanceof AbstractHttpException
@@ -90,6 +61,51 @@ class Handler extends ExceptionHandler
return parent::render($request, $exception); return parent::render($request, $exception);
} }
/**
* Handle errors in the API
*
* @param $request
* @param \Exception $exception
*
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
*/
private function handleApiError($request, Exception $exception)
{
Log::error('API Error', $exception->getTrace());
if ($exception instanceof AbstractHttpException) {
return $exception->getResponse();
}
/*
* Not of the HttpException abstract class. Map these into
*/
if ($exception instanceof ModelNotFoundException || $exception instanceof NotFoundHttpException) {
$error = new AssetNotFound($exception);
return $error->getResponse();
}
// Custom exceptions should be extending HttpException
if ($exception instanceof SymfonyHttpException) {
$error = new SymfonyException($exception);
return $error->getResponse();
}
// Create the detailed errors from the validation errors
if ($exception instanceof IlluminateValidationException) {
$error = new ValidationException($exception);
return $error->getResponse();
}
$error = new GenericExceptionAbstract($exception);
return $error->getResponse();
}
/** /**
* Convert an authentication exception into an unauthenticated response. * Convert an authentication exception into an unauthenticated response.
* *
Generated
+195 -195
View File
File diff suppressed because it is too large Load Diff
@@ -23,7 +23,7 @@ class UpdateServiceProvider extends ServiceProvider
Route::group([ Route::group([
'as' => 'update.', 'as' => 'update.',
'prefix' => 'update', 'prefix' => 'update',
'middleware' => ['auth', 'ability:admin,admin-access', 'web'], 'middleware' => ['web', 'auth', 'ability:admin,admin-access'],
'namespace' => 'Modules\Updater\Http\Controllers', 'namespace' => 'Modules\Updater\Http\Controllers',
], function () { ], function () {
Route::get('/', 'UpdateController@index')->name('index'); Route::get('/', 'UpdateController@index')->name('index');
+1 -1
View File
@@ -1,4 +1,4 @@
FROM php:7.3-fpm-alpine FROM php:7.4-fpm-alpine
RUN apk add make gmp-dev RUN apk add make gmp-dev
@@ -36,7 +36,7 @@
<div class="icon-background"> {{--110px font-size--}} <div class="icon-background"> {{--110px font-size--}}
<i class="fas fa-money-bill-alt icon"></i> <i class="fas fa-money-bill-alt icon"></i>
</div> </div>
<h3 class="header">{{ $user->journal->balance }}</h3> <h3 class="header">{{ optional($user->journal)->balance ?? 0 }}</h3>
<h5 class="description">@lang('dashboard.yourbalance')</h5> <h5 class="description">@lang('dashboard.yourbalance')</h5>
</div> </div>
</div> </div>
@@ -93,11 +93,11 @@
<i class="far fa-user"></i>&nbsp;&nbsp;@lang('common.profile') <i class="far fa-user"></i>&nbsp;&nbsp;@lang('common.profile')
</a> </a>
@role('admin') @ability('admin', 'admin-access')
<a class="dropdown-item" href="{{ url('/admin') }}"> <a class="dropdown-item" href="{{ url('/admin') }}">
<i class="fas fa-circle-notch"></i>&nbsp;&nbsp;@lang('common.administration') <i class="fas fa-circle-notch"></i>&nbsp;&nbsp;@lang('common.administration')
</a> </a>
@endrole @endability
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ url('/logout') }}"> <a class="dropdown-item" href="{{ url('/logout') }}">
<i class="fas fa-sign-out-alt"></i>&nbsp;&nbsp;@lang('common.logout') <i class="fas fa-sign-out-alt"></i>&nbsp;&nbsp;@lang('common.logout')