## Summary - replace the legacy Tenant and TenantMembership core models with ManagedEnvironment and ManagedEnvironmentMembership - propagate the managed environment naming and key changes across Filament resources, pages, controllers, jobs, models, and supporting runtime paths - add feature 279 spec artifacts and focused managed-environment test coverage for model behavior, route binding, panel context, authorization, and legacy guardrails ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/ManagedEnvironment/LegacyTenantCoreGuardTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentAuthorizationTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentPanelContextTest.php tests/Feature/ManagedEnvironment/ManagedEnvironmentRouteBindingTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentContextResolverTest.php tests/Unit/ManagedEnvironment/ManagedEnvironmentModelTest.php` - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` ## Notes - branch pushed from commit `1123b122` - browser smoke test file was added but not run in this pass Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #335
111 lines
3.6 KiB
PHP
111 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Models\WorkspaceMembership;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
Http::preventStrayRequests();
|
|
});
|
|
|
|
it('serves the Workspaces UI tenantless at /admin/workspaces', function (): void {
|
|
$user = User::factory()->create();
|
|
|
|
$workspace = Workspace::factory()->create(['slug' => 'acme']);
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => $workspace->getKey(),
|
|
'user_id' => $user->getKey(),
|
|
'role' => 'owner',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
|
|
->get('/admin/workspaces')
|
|
->assertOk();
|
|
});
|
|
|
|
it('serves /admin/workspaces without an active workspace selected (Global Mode)', function (): void {
|
|
$user = User::factory()->create();
|
|
|
|
$workspace = Workspace::factory()->create(['slug' => 'acme']);
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => $workspace->getKey(),
|
|
'user_id' => $user->getKey(),
|
|
'role' => 'owner',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->get('/admin/workspaces')
|
|
->assertOk()
|
|
->assertSee('Choose workspace')
|
|
->assertSee('Choose a workspace first.');
|
|
});
|
|
|
|
it('serves the Workspaces view page tenantless at /admin/workspaces/{record}', function (): void {
|
|
$user = User::factory()->create();
|
|
|
|
$workspace = Workspace::factory()->create(['slug' => 'acme']);
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => $workspace->getKey(),
|
|
'user_id' => $user->getKey(),
|
|
'role' => 'owner',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
|
|
->get('/admin/workspaces/'.(int) $workspace->getKey())
|
|
->assertOk();
|
|
});
|
|
|
|
it('does not expose the Workspaces UI under the tenant route prefix', function (): void {
|
|
$user = User::factory()->create();
|
|
|
|
$workspace = Workspace::factory()->create(['slug' => 'acme']);
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => $workspace->getKey(),
|
|
'user_id' => $user->getKey(),
|
|
'role' => 'owner',
|
|
]);
|
|
|
|
$tenant = ManagedEnvironment::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'external_id' => '11111111-1111-1111-1111-111111111111',
|
|
'managed_environment_id' => '11111111-1111-1111-1111-111111111111',
|
|
]);
|
|
|
|
$user->tenants()->syncWithoutDetaching([
|
|
$tenant->getKey() => ['role' => 'owner'],
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()])
|
|
->get('/admin/t/11111111-1111-1111-1111-111111111111/workspaces')
|
|
->assertNotFound();
|
|
});
|
|
|
|
it('returns 404 when accessing a workspace record outside membership', function (): void {
|
|
$user = User::factory()->create();
|
|
|
|
$workspaceA = Workspace::factory()->create(['slug' => 'acme-a']);
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => $workspaceA->getKey(),
|
|
'user_id' => $user->getKey(),
|
|
'role' => 'owner',
|
|
]);
|
|
|
|
$workspaceB = Workspace::factory()->create(['slug' => 'acme-b']);
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspaceA->getKey()])
|
|
->get('/admin/workspaces/'.(int) $workspaceB->getKey())
|
|
->assertNotFound();
|
|
});
|