TenantAtlas/apps/platform/app/Http/Controllers/ClearEnvironmentContextController.php
ahmido b159dacd36 feat: clean up legacy tenant environment context (#372)
## Summary
- remove legacy tenant-scoped routing and middleware paths in favor of the current environment/workspace context flow
- update Filament pages and resources to use the cleaned-up admin surface and environment filter context
- add the related spec 317 artifacts and targeted tests for environment filter state and legacy context cleanup

## Testing
- not run as part of this commit/push/PR workflow

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #372
2026-05-16 18:25:36 +00:00

67 lines
2.0 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
{
if ($previousPath === '/admin/evidence') {
return true;
}
if (! str_starts_with($previousPath, '/admin/evidence/')) {
return false;
}
return ! str_starts_with($previousPath, '/admin/evidence/overview');
}
}