Implements Spec 080: split Filament into workspace-managed `/admin/*` (manage) vs tenant operations `/admin/t/{tenant}/*` (operate).
Highlights:
- Adds tenant operations panel (`tenant`) at `/admin/t` with tenancy by `Tenant.external_id`
- Keeps management resources in workspace panel (`admin`) under `/admin/tenants/*`
- Moves Provider Connections to workspace-managed routes: `/admin/tenants/{tenant}/provider-connections`
- Adds discoverability CTA on tenant view (Actions → Provider connections)
- Adds/updates Pest regression tests for routing boundaries, 404/403 RBAC-UX semantics, and global search isolation
- Includes full Spec Kit artifacts under `specs/080-workspace-managed-tenant-admin/`
Validation:
- `vendor/bin/sail bin pint --dirty`
- `vendor/bin/sail artisan test --compact tests/Feature/Spec080WorkspaceManagedTenantAdminMigrationTest.php`
Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box>
Reviewed-on: #97
75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Filament\Pages\ChooseTenant;
|
|
use App\Filament\Pages\TenantDashboard;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use App\Support\Workspaces\WorkspaceIntendedUrl;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
final class SwitchWorkspaceController
|
|
{
|
|
public function __invoke(Request $request): RedirectResponse
|
|
{
|
|
$user = auth()->user();
|
|
|
|
if (! $user instanceof User) {
|
|
abort(403);
|
|
}
|
|
|
|
$validated = $request->validate([
|
|
'workspace_id' => ['required', 'integer'],
|
|
]);
|
|
|
|
$workspace = Workspace::query()->whereKey($validated['workspace_id'])->first();
|
|
|
|
if (! $workspace instanceof Workspace) {
|
|
abort(404);
|
|
}
|
|
|
|
if (! empty($workspace->archived_at)) {
|
|
abort(404);
|
|
}
|
|
|
|
$context = app(WorkspaceContext::class);
|
|
|
|
if (! $context->isMember($user, $workspace)) {
|
|
abort(404);
|
|
}
|
|
|
|
$context->setCurrentWorkspace($workspace, $user, $request);
|
|
|
|
$intendedUrl = WorkspaceIntendedUrl::consume($request);
|
|
|
|
if ($intendedUrl !== null) {
|
|
return redirect()->to($intendedUrl);
|
|
}
|
|
|
|
$tenantsQuery = $user->tenants()
|
|
->where('workspace_id', $workspace->getKey())
|
|
->where('status', 'active');
|
|
|
|
$tenantCount = (int) $tenantsQuery->count();
|
|
|
|
if ($tenantCount === 0) {
|
|
return redirect()->route('admin.onboarding');
|
|
}
|
|
|
|
if ($tenantCount === 1) {
|
|
$tenant = $tenantsQuery->first();
|
|
|
|
if ($tenant !== null) {
|
|
return redirect()->to(TenantDashboard::getUrl(panel: 'tenant', tenant: $tenant));
|
|
}
|
|
}
|
|
|
|
return redirect()->to(ChooseTenant::getUrl());
|
|
}
|
|
}
|