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:
commit
ee1c8ee3fa
7
Makefile
7
Makefile
@ -29,6 +29,13 @@ clean:
|
|||||||
clean-routes:
|
clean-routes:
|
||||||
@php artisan route:clear
|
@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
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
@php $(COMPOSER) install --no-interaction
|
@php $(COMPOSER) install --no-interaction
|
||||||
|
@ -36,7 +36,7 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function commands(): void
|
protected function commands(): void
|
||||||
{
|
{
|
||||||
require app_path('Routes/console.php');
|
require app_path('Http/Routes/console.php');
|
||||||
$this->load(__DIR__.'/Commands');
|
$this->load(__DIR__.'/Commands');
|
||||||
$this->load(__DIR__.'/Cron');
|
$this->load(__DIR__.'/Cron');
|
||||||
}
|
}
|
||||||
|
@ -7,16 +7,13 @@ use App\Facades\Utils;
|
|||||||
use App\Repositories\NewsRepository;
|
use App\Repositories\NewsRepository;
|
||||||
use App\Repositories\PirepRepository;
|
use App\Repositories\PirepRepository;
|
||||||
use App\Repositories\UserRepository;
|
use App\Repositories\UserRepository;
|
||||||
use Auth;
|
|
||||||
use Flash;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Log;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Version;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Laracasts\Flash\Flash;
|
||||||
|
use SebastianBergmann\Version;
|
||||||
use vierbergenlars\SemVer\version as semver;
|
use vierbergenlars\SemVer\version as semver;
|
||||||
|
|
||||||
/**
|
|
||||||
* Class DashboardController
|
|
||||||
*/
|
|
||||||
class DashboardController extends Controller
|
class DashboardController extends Controller
|
||||||
{
|
{
|
||||||
private $newsRepo;
|
private $newsRepo;
|
||||||
|
@ -2,41 +2,60 @@
|
|||||||
|
|
||||||
namespace App\Http;
|
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\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
|
class Kernel extends HttpKernel
|
||||||
{
|
{
|
||||||
protected $middleware = [
|
protected $middleware = [
|
||||||
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
|
CheckForMaintenanceMode::class,
|
||||||
\Illuminate\Foundation\Http\Middleware\TrimStrings::class,
|
TrimStrings::class,
|
||||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::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' => [
|
'api' => [
|
||||||
'throttle:60,1',
|
'throttle:60,1',
|
||||||
'bindings',
|
'bindings',
|
||||||
'json',
|
'json',
|
||||||
],
|
],
|
||||||
|
'web' => [
|
||||||
|
InstalledCheck::class,
|
||||||
|
EncryptCookies::class,
|
||||||
|
AddQueuedCookiesToResponse::class,
|
||||||
|
StartSession::class,
|
||||||
|
ShareErrorsFromSession::class,
|
||||||
|
VerifyCsrfToken::class,
|
||||||
|
SubstituteBindings::class,
|
||||||
|
//\Spatie\Pjax\Middleware\FilterIfPjax::class,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
protected $routeMiddleware = [
|
protected $routeMiddleware = [
|
||||||
'api.auth' => \App\Http\Middleware\ApiAuth::class,
|
'api.auth' => ApiAuth::class,
|
||||||
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
|
'auth' => Authenticate::class,
|
||||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
'auth.basic' => AuthenticateWithBasicAuth::class,
|
||||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
'bindings' => SubstituteBindings::class,
|
||||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
'can' => Authorize::class,
|
||||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
'guest' => RedirectIfAuthenticated::class,
|
||||||
'json' => \App\Http\Middleware\JsonResponse::class,
|
'json' => JsonResponse::class,
|
||||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
'throttle' => ThrottleRequests::class,
|
||||||
|
'update_pending' => UpdatePending::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
39
app/Http/Middleware/UpdatePending.php
Normal file
39
app/Http/Middleware/UpdatePending.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
Route::group([
|
Route::group([
|
||||||
'namespace' => 'Admin', 'prefix' => 'admin', 'as' => 'admin.',
|
'namespace' => 'Admin', 'prefix' => 'admin', 'as' => 'admin.',
|
||||||
'middleware' => ['ability:admin,admin-access'],
|
'middleware' => ['update_pending', 'ability:admin,admin-access'],
|
||||||
], static function () {
|
], static function () {
|
||||||
// CRUD for airlines
|
// CRUD for airlines
|
||||||
Route::resource('airlines', 'AirlinesController');
|
Route::resource('airlines', 'AirlinesController');
|
@ -47,4 +47,4 @@ Route::group([
|
|||||||
Auth::routes(['verify' => true]);
|
Auth::routes(['verify' => true]);
|
||||||
Route::get('/logout', 'Auth\LoginController@logout')->name('logout');
|
Route::get('/logout', 'Auth\LoginController@logout')->name('logout');
|
||||||
|
|
||||||
require app_path('Routes/admin.php');
|
require app_path('Http/Routes/admin.php');
|
@ -40,7 +40,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
'middleware' => 'web',
|
'middleware' => 'web',
|
||||||
'namespace' => $this->namespace,
|
'namespace' => $this->namespace,
|
||||||
], function ($router) {
|
], 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',
|
'prefix' => 'api',
|
||||||
'as' => 'api.',
|
'as' => 'api.',
|
||||||
], function ($router) {
|
], function ($router) {
|
||||||
require app_path('Routes/api.php');
|
require app_path('Http/Routes/api.php');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,61 +158,17 @@ return [
|
|||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Laratrust Foreign Keys
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| These are the foreign keys used by laratrust in the intermediate tables.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
'foreign_keys' => [
|
'foreign_keys' => [
|
||||||
/*
|
'user' => 'user_id',
|
||||||
* User foreign key on Laratrust's role_user and permission_user tables.
|
'role' => 'role_id',
|
||||||
*/
|
|
||||||
'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',
|
'permission' => 'permission_id',
|
||||||
|
'team' => 'team_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' => [
|
'middleware' => [
|
||||||
/*
|
|
||||||
* Define if the laratrust middleware are registered automatically in the service provider
|
|
||||||
*/
|
|
||||||
'register' => true,
|
'register' => true,
|
||||||
|
'handling' => 'redirect',
|
||||||
/*
|
'params' => '/login',
|
||||||
* Method to be called in the middleware return case.
|
|
||||||
* Available: abort|redirect
|
|
||||||
*/
|
|
||||||
'handling' => 'abort',
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Parameter passed to the middleware_handling method
|
|
||||||
*/
|
|
||||||
'params' => '403',
|
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user