## Summary - enforce the canonical workspace/environment scope contract for workspace hubs and environment-owned surfaces - replace first-party Operations deep links that leaked Filament `tableFilters[...]` internals with stable product-level query behavior - add the sidebar scope indicator and split environment-page navigation into explicit `Workspace-wide` and `Workspace admin` groups - remove redundant tenantless `All environments` scope badges from workspace-wide pages while preserving explicit environment filter affordances - include the Spec 338 artifacts, guard tests, and browser smoke coverage for the new contract ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Navigation/Spec338EnvironmentSidebarSeparationTest.php tests/Feature/Navigation/Spec338OperationRunLinksQueryContractTest.php tests/Feature/Navigation/Spec338SidebarScopeIndicatorTest.php tests/Feature/Filament/PanelNavigationSegregationTest.php` - `cd apps/platform && ./vendor/bin/sail php vendor/bin/pest tests/Browser/Spec338ScopeContractSmokeTest.php --compact` ## Notes - Livewire v4 compliance unchanged - Filament provider registration remains in `bootstrap/providers.php` - no destructive action behavior changed - no migrations, env var changes, or new Filament asset registration Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #409
61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Support\Navigation\AdminSurfaceScope;
|
|
use App\Support\OperationRunLinks;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
final class ClearEnvironmentContextController
|
|
{
|
|
public function __invoke(Request $request): RedirectResponse
|
|
{
|
|
Filament::setTenant(null, true);
|
|
|
|
$workspaceContext = app(WorkspaceContext::class);
|
|
|
|
$workspaceContext->clearRememberedEnvironmentContext($request);
|
|
|
|
$previousUrl = url()->previous();
|
|
|
|
$previousHost = parse_url((string) $previousUrl, PHP_URL_HOST);
|
|
$previousPath = (string) (parse_url((string) $previousUrl, PHP_URL_PATH) ?? '');
|
|
|
|
if ($previousHost !== null && $previousHost !== $request->getHost()) {
|
|
return redirect()->to(OperationRunLinks::index());
|
|
}
|
|
|
|
if ($this->isEnvironmentScopedEvidencePath($previousPath)) {
|
|
return redirect()->route('admin.evidence.overview');
|
|
}
|
|
|
|
if (AdminSurfaceScope::fromPath($previousPath) === AdminSurfaceScope::EnvironmentBound) {
|
|
$workspace = $workspaceContext->currentWorkspace($request);
|
|
|
|
if ($workspace !== null) {
|
|
return redirect()->route('admin.workspace.managed-environments.index', ['workspace' => $workspace]);
|
|
}
|
|
|
|
return redirect()->route('admin.home');
|
|
}
|
|
|
|
if ($previousPath === '' || $previousPath === '/admin/clear-environment-context') {
|
|
return redirect()->to(OperationRunLinks::index());
|
|
}
|
|
|
|
return redirect()->to((string) $previousUrl);
|
|
}
|
|
|
|
private function isEnvironmentScopedEvidencePath(string $previousPath): bool
|
|
{
|
|
$normalizedPath = '/'.ltrim($previousPath, '/');
|
|
|
|
return preg_match('#^/admin/workspaces/[^/]+/environments/[^/]+/evidence(?:/|$)#', $normalizedPath) === 1;
|
|
}
|
|
}
|