## Summary - consolidate internal platform naming from `Tenant` to `Environment` / `ManagedEnvironment` across models, controllers, services, and Filament resources - rename environment-scoped UI surfaces such as dashboards, chooser flows, navigation, and related widgets to match the updated environment-first domain language - align middleware, onboarding/review lifecycle services, jobs, and route/context controllers with the new environment-scoped architecture ## Validation - not rerun as part of this commit/push/PR request ## Notes - branch is 1 commit ahead of `platform-dev` - main commit: `refactor: consolidate internal tenant model naming` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #355
78 lines
3.0 KiB
PHP
78 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\FindingResource;
|
|
use App\Models\Finding;
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Models\WorkspaceMembership;
|
|
use App\Services\Auth\ManagedEnvironmentMembershipManager;
|
|
use App\Services\Auth\WorkspaceMembershipManager;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
pest()->browser()->timeout(20_000);
|
|
|
|
it('smokes workspace role management plus scoped environment drilldown', function (): void {
|
|
$workspace = Workspace::factory()->create([
|
|
'name' => 'Spec 285 Workspace',
|
|
]);
|
|
$allowedTenant = ManagedEnvironment::factory()->active()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'name' => 'Spec 285 Allowed',
|
|
'slug' => 'spec-285-allowed',
|
|
]);
|
|
$deniedTenant = ManagedEnvironment::factory()->active()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'name' => 'Spec 285 Denied',
|
|
'slug' => 'spec-285-denied',
|
|
]);
|
|
$owner = User::factory()->create();
|
|
$member = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $owner->getKey(),
|
|
'role' => 'owner',
|
|
]);
|
|
$memberMembership = WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $member->getKey(),
|
|
'role' => 'readonly',
|
|
]);
|
|
|
|
app(WorkspaceMembershipManager::class)->changeRole($workspace, $owner, $memberMembership, 'operator');
|
|
app(ManagedEnvironmentMembershipManager::class)->grantScope($allowedTenant, $owner, $member, source: 'manual');
|
|
|
|
Finding::factory()->for($allowedTenant)->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'severity' => Finding::SEVERITY_HIGH,
|
|
]);
|
|
|
|
$this->actingAs($member)->withSession([
|
|
WorkspaceContext::SESSION_KEY => (int) $workspace->getKey(),
|
|
]);
|
|
session()->put(WorkspaceContext::SESSION_KEY, (int) $workspace->getKey());
|
|
|
|
$managedEnvironmentsPath = (string) parse_url(route('admin.workspace.managed-environments.index', ['workspace' => $workspace]), PHP_URL_PATH);
|
|
$findingsIndexPath = (string) parse_url(FindingResource::getUrl('index', tenant: $allowedTenant, panel: 'admin'), PHP_URL_PATH);
|
|
|
|
visit(route('admin.workspace.managed-environments.index', ['workspace' => $workspace]))
|
|
->waitForText('Spec 285 Allowed')
|
|
->assertScript("window.location.pathname === '{$managedEnvironmentsPath}'", true)
|
|
->assertSee('Spec 285 Allowed')
|
|
->assertDontSee('Spec 285 Denied')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs();
|
|
|
|
visit(FindingResource::getUrl('index', tenant: $allowedTenant, panel: 'admin'))
|
|
->waitForText('Findings')
|
|
->assertScript("window.location.pathname === '{$findingsIndexPath}'", true)
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoConsoleLogs();
|
|
});
|