Merge pull request #328 from nabeelio/328/pending-updates

Middleware to detect is update is pending; move Routes into HTTP
This commit is contained in:
Nabeel S 2019-07-18 11:07:22 -04:00 committed by GitHub
commit ee1c8ee3fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 101 additions and 83 deletions

View File

@ -29,6 +29,13 @@ clean:
clean-routes:
@php artisan route:clear
.PHONY: clear
clear:
@php artisan cache:clear
@php artisan config:clear
@php artisan route:clear
@php artisan view:clear
.PHONY: build
build:
@php $(COMPOSER) install --no-interaction

View File

@ -36,7 +36,7 @@ class Kernel extends ConsoleKernel
*/
protected function commands(): void
{
require app_path('Routes/console.php');
require app_path('Http/Routes/console.php');
$this->load(__DIR__.'/Commands');
$this->load(__DIR__.'/Cron');
}

View File

@ -7,16 +7,13 @@ use App\Facades\Utils;
use App\Repositories\NewsRepository;
use App\Repositories\PirepRepository;
use App\Repositories\UserRepository;
use Auth;
use Flash;
use Illuminate\Http\Request;
use Log;
use Version;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Laracasts\Flash\Flash;
use SebastianBergmann\Version;
use vierbergenlars\SemVer\version as semver;
/**
* Class DashboardController
*/
class DashboardController extends Controller
{
private $newsRepo;

View File

@ -2,41 +2,60 @@
namespace App\Http;
use App\Http\Middleware\ApiAuth;
use App\Http\Middleware\EncryptCookies;
use App\Http\Middleware\InstalledCheck;
use App\Http\Middleware\JsonResponse;
use App\Http\Middleware\RedirectIfAuthenticated;
use App\Http\Middleware\UpdatePending;
use App\Http\Middleware\VerifyCsrfToken;
use Illuminate\Auth\Middleware\Authenticate;
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
use Illuminate\Foundation\Http\Middleware\TrimStrings;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
class Kernel extends HttpKernel
{
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
CheckForMaintenanceMode::class,
TrimStrings::class,
ConvertEmptyStringsToNull::class,
];
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\InstalledCheck::class,
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
//\Spatie\Pjax\Middleware\FilterIfPjax::class,
],
protected $middlewareGroups = [
'api' => [
'throttle:60,1',
'bindings',
'json',
],
'web' => [
InstalledCheck::class,
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
//\Spatie\Pjax\Middleware\FilterIfPjax::class,
],
];
protected $routeMiddleware = [
'api.auth' => \App\Http\Middleware\ApiAuth::class,
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'json' => \App\Http\Middleware\JsonResponse::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'api.auth' => ApiAuth::class,
'auth' => Authenticate::class,
'auth.basic' => AuthenticateWithBasicAuth::class,
'bindings' => SubstituteBindings::class,
'can' => Authorize::class,
'guest' => RedirectIfAuthenticated::class,
'json' => JsonResponse::class,
'throttle' => ThrottleRequests::class,
'update_pending' => UpdatePending::class,
];
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Determine if an update is pending by checking if there are available migrations
* Redirect to the updater if there are. Done as middlware so it can happen before
* any authentication checks when someone goes to the admin panel
*/
namespace App\Http\Middleware;
use App\Services\Installer\MigrationService;
use Closure;
class UpdatePending
{
private $migrationSvc;
/**
* @param MigrationService $migrationSvc
*/
public function __construct(MigrationService $migrationSvc)
{
$this->migrationSvc = $migrationSvc;
}
/**
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
if (count($this->migrationSvc->migrationsAvailable()) > 0) {
return redirect('/update/step1');
}
return $next($request);
}
}

View File

@ -4,7 +4,7 @@
*/
Route::group([
'namespace' => 'Admin', 'prefix' => 'admin', 'as' => 'admin.',
'middleware' => ['ability:admin,admin-access'],
'middleware' => ['update_pending', 'ability:admin,admin-access'],
], static function () {
// CRUD for airlines
Route::resource('airlines', 'AirlinesController');

View File

@ -47,4 +47,4 @@ Route::group([
Auth::routes(['verify' => true]);
Route::get('/logout', 'Auth\LoginController@logout')->name('logout');
require app_path('Routes/admin.php');
require app_path('Http/Routes/admin.php');

View File

@ -40,7 +40,7 @@ class RouteServiceProvider extends ServiceProvider
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require app_path('Routes/web.php');
require app_path('Http/Routes/web.php');
});
}
@ -59,7 +59,7 @@ class RouteServiceProvider extends ServiceProvider
'prefix' => 'api',
'as' => 'api.',
], function ($router) {
require app_path('Routes/api.php');
require app_path('Http/Routes/api.php');
});
}
}

View File

@ -158,61 +158,17 @@ return [
],
/*
|--------------------------------------------------------------------------
| Laratrust Foreign Keys
|--------------------------------------------------------------------------
|
| These are the foreign keys used by laratrust in the intermediate tables.
|
*/
'foreign_keys' => [
/*
* User foreign key on Laratrust's role_user and permission_user tables.
*/
'user' => 'user_id',
/*
* Role foreign key on Laratrust's role_user and permission_role tables.
*/
'role' => 'role_id',
/*
* Role foreign key on Laratrust's permission_user and permission_role tables.
*/
'permission' => 'permission_id',
/*
* Role foreign key on Laratrust's role_user and permission_user tables.
*/
'team' => 'team_id',
],
/*
|--------------------------------------------------------------------------
| Laratrust Middleware
|--------------------------------------------------------------------------
|
| This configuration helps to customize the Laratrust middleware behavior.
|
*/
'middleware' => [
/*
* Define if the laratrust middleware are registered automatically in the service provider
*/
'register' => true,
/*
* Method to be called in the middleware return case.
* Available: abort|redirect
*/
'handling' => 'abort',
/*
* Parameter passed to the middleware_handling method
*/
'params' => '403',
'handling' => 'redirect',
'params' => '/login',
],