57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class ForceFilamentUiMiddleware
|
|
{
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
if (! (bool) config('netgescon.ui.force_filament', false)) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Keep Filament panel and non-admin paths untouched.
|
|
$isLegacyAdminPath = $request->is('admin') || $request->is('admin/*');
|
|
$isFilamentPath = $request->is('admin-filament') || $request->is('admin-filament/*');
|
|
|
|
if (! $isLegacyAdminPath || $isFilamentPath) {
|
|
return $next($request);
|
|
}
|
|
|
|
if ($this->shouldBypassRedirect($request)) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Redirect only navigational requests. Non-GET calls are left as-is.
|
|
if (! $request->isMethod('GET') && ! $request->isMethod('HEAD')) {
|
|
return $next($request);
|
|
}
|
|
|
|
return redirect('/admin-filament');
|
|
}
|
|
|
|
private function shouldBypassRedirect(Request $request): bool
|
|
{
|
|
foreach ([
|
|
'admin/fatture-elettroniche/*/download-xml',
|
|
'admin/fatture-elettroniche/*/download-pdf',
|
|
'admin/tickets/attachments/*/view',
|
|
'admin/insurance-policies/*/assets/*',
|
|
'admin/documenti/*/download',
|
|
'admin/documenti-collegati/*/download',
|
|
'admin/contabilita-gescon/documenti/*/download',
|
|
'admin/filament/import-inbox/*/download',
|
|
'admin/filament/tickets/attachments/*/view',
|
|
] as $pattern) {
|
|
if ($request->is($pattern)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|