## 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
133 lines
5.0 KiB
PHP
133 lines
5.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\InventoryItemResource;
|
|
use App\Filament\Resources\RestoreRunResource;
|
|
use App\Models\ManagedEnvironment;
|
|
use App\Models\OperationRun;
|
|
use App\Models\RestoreRun;
|
|
use App\Support\OperationRunLinks;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
final class RelatedLinksOnDetailTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_shows_restore_related_links_on_canonical_detail_for_restore_execute_runs(): void
|
|
{
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$restoreRun = RestoreRun::factory()->create([
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
]);
|
|
|
|
$run = OperationRun::factory()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
'type' => 'restore.execute',
|
|
'context' => [
|
|
'restore_run_id' => (int) $restoreRun->getKey(),
|
|
],
|
|
]);
|
|
|
|
$expectedUrl = RestoreRunResource::getUrl('view', ['record' => $restoreRun], tenant: $tenant);
|
|
|
|
$response = $this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
|
|
->get(\App\Support\OperationRunLinks::tenantlessView($run))
|
|
->assertOk()
|
|
->assertSee('Open')
|
|
->assertSee('View restore run');
|
|
|
|
$response->assertSee((string) $expectedUrl, false);
|
|
}
|
|
|
|
public function test_shows_only_generic_links_for_tenantless_runs_on_canonical_detail(): void
|
|
{
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$run = OperationRun::factory()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'managed_environment_id' => null,
|
|
'type' => 'restore.execute',
|
|
'context' => [
|
|
'restore_run_id' => 999,
|
|
],
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
|
|
->get(\App\Support\OperationRunLinks::tenantlessView($run))
|
|
->assertOk()
|
|
->assertSee('Operations')
|
|
->assertSee(OperationRunLinks::index(), false)
|
|
->assertDontSee('View restore run');
|
|
}
|
|
|
|
public function test_does_not_show_legacy_admin_details_cta_and_keeps_canonical_view_run_label(): void
|
|
{
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$run = OperationRun::factory()->create([
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
'managed_environment_id' => (int) $tenant->getKey(),
|
|
'type' => 'policy.sync',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
|
|
->get(\App\Support\OperationRunLinks::tenantlessView($run))
|
|
->assertOk()
|
|
->assertDontSee('Admin details')
|
|
->assertDontSee('/admin/t/'.$tenant->external_id.'/operations/r/'.$run->getKey(), false);
|
|
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id])
|
|
->get(OperationRunLinks::index())
|
|
->assertOk()
|
|
->assertSee('Open run detail');
|
|
}
|
|
|
|
public function test_hides_tenant_scoped_follow_up_links_when_the_run_tenant_is_not_selector_eligible(): void
|
|
{
|
|
$activeEnvironment = ManagedEnvironment::factory()->active()->create([
|
|
'name' => 'Viewer Active ManagedEnvironment',
|
|
]);
|
|
[$user, $activeEnvironment] = createUserWithTenant(tenant: $activeEnvironment, role: 'owner');
|
|
|
|
$onboardingTenant = ManagedEnvironment::factory()->onboarding()->create([
|
|
'workspace_id' => (int) $activeEnvironment->workspace_id,
|
|
'name' => 'Viewer Onboarding ManagedEnvironment',
|
|
]);
|
|
|
|
createUserWithTenant(
|
|
tenant: $onboardingTenant,
|
|
user: $user,
|
|
role: 'owner',
|
|
workspaceRole: 'owner',
|
|
ensureDefaultMicrosoftProviderConnection: false,
|
|
);
|
|
|
|
$run = OperationRun::factory()->create([
|
|
'workspace_id' => (int) $activeEnvironment->workspace_id,
|
|
'managed_environment_id' => (int) $onboardingTenant->getKey(),
|
|
'type' => 'inventory_sync',
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $activeEnvironment->workspace_id])
|
|
->get(\App\Support\OperationRunLinks::tenantlessView($run))
|
|
->assertOk()
|
|
->assertSee('Open')
|
|
->assertSee('Operations')
|
|
->assertDontSee(InventoryItemResource::getUrl('index', panel: 'admin', tenant: $onboardingTenant), false)
|
|
->assertSee('Some tenant follow-up actions may be unavailable from this canonical workspace view.');
|
|
}
|
|
}
|