## Summary - introduce a canonical admin tenant filter-state helper and route all in-scope workspace-admin tenant resolution through `OperateHubShell::activeEntitledTenant()` - align operations monitoring, operation-run deep links, Entra group admin list/view/search behavior, and shared context-bar rendering with the documented scope contract - add the Spec 135 design artifacts, architecture note, focused guardrail coverage, and non-regression tests for filter persistence, direct-record access, and global search safety ## Validation - `vendor/bin/sail bin pint --dirty --format agent` - `vendor/bin/sail artisan test --compact tests/Feature/Monitoring/OperationsKpiHeaderTenantContextTest.php tests/Feature/Monitoring/OperationsTenantScopeTest.php tests/Feature/Monitoring/OperationsCanonicalUrlsTest.php tests/Feature/Spec085/OperationsIndexHeaderTest.php tests/Feature/Spec085/RunDetailBackAffordanceTest.php tests/Feature/Filament/OperationRunListFiltersTest.php tests/Feature/Filament/EntraGroupAdminScopeTest.php tests/Feature/Filament/EntraGroupGlobalSearchScopeTest.php tests/Feature/DirectoryGroups/BrowseGroupsTest.php tests/Feature/Filament/EntraGroupEnterpriseDetailPageTest.php tests/Feature/Filament/PolicyVersionResolvedReferenceLinksTest.php tests/Feature/Filament/EntraGroupResolvedReferencePresentationTest.php tests/Feature/Guards/AdminTenantResolverGuardTest.php tests/Feature/OpsUx/OperateHubShellTest.php tests/Feature/Filament/Alerts/AlertsKpiHeaderTest.php tests/Feature/Alerts/AlertDeliveryDeepLinkFiltersTest.php` - `vendor/bin/sail artisan test --compact tests/Feature/Filament/TableStatePersistenceTest.php tests/Feature/Filament/TenantScopingTest.php tests/Feature/Filament/Alerts/AlertDeliveryViewerTest.php tests/Unit/Support/References/CapabilityAwareReferenceResolverTest.php` ## Notes - Filament v5 remains on Livewire v4.0+ compliant surfaces only. - No provider registration changes were needed; Laravel 12 provider registration remains in `bootstrap/providers.php`. - Entra group global search remains enabled and is now scoped to the canonical admin tenant contract. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #164
208 lines
7.2 KiB
PHP
208 lines
7.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Widgets\Alerts\AlertsKpiHeader;
|
|
use App\Models\AlertDelivery;
|
|
use App\Models\AlertDestination;
|
|
use App\Models\AlertRule;
|
|
use App\Models\Tenant;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
|
use Livewire\Livewire;
|
|
|
|
function alertsKpiValues($component): array
|
|
{
|
|
$method = new ReflectionMethod(AlertsKpiHeader::class, 'getStats');
|
|
$method->setAccessible(true);
|
|
|
|
return collect($method->invoke($component->instance()))
|
|
->mapWithKeys(fn (Stat $stat): array => [
|
|
(string) $stat->getLabel() => (string) $stat->getValue(),
|
|
])
|
|
->all();
|
|
}
|
|
|
|
it('filters KPI deliveries by tenant when context is set via lastTenantId fallback only', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$workspaceId = (int) $tenant->workspace_id;
|
|
|
|
$rule = AlertRule::factory()->create(['workspace_id' => $workspaceId]);
|
|
$destination = AlertDestination::factory()->create(['workspace_id' => $workspaceId]);
|
|
|
|
AlertDelivery::factory()->create([
|
|
'workspace_id' => $workspaceId,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'alert_rule_id' => (int) $rule->getKey(),
|
|
'alert_destination_id' => (int) $destination->getKey(),
|
|
'status' => AlertDelivery::STATUS_SENT,
|
|
'created_at' => now()->subHour(),
|
|
]);
|
|
|
|
$otherTenant = Tenant::factory()->create(['workspace_id' => $workspaceId]);
|
|
$user->tenants()->syncWithoutDetaching([
|
|
$otherTenant->getKey() => ['role' => 'owner'],
|
|
]);
|
|
|
|
AlertDelivery::factory()->create([
|
|
'workspace_id' => $workspaceId,
|
|
'tenant_id' => (int) $otherTenant->getKey(),
|
|
'alert_rule_id' => (int) $rule->getKey(),
|
|
'alert_destination_id' => (int) $destination->getKey(),
|
|
'status' => AlertDelivery::STATUS_SENT,
|
|
'created_at' => now()->subHour(),
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
Filament::setTenant(null, true);
|
|
|
|
session()->put(WorkspaceContext::SESSION_KEY, $workspaceId);
|
|
session()->put(WorkspaceContext::LAST_TENANT_IDS_SESSION_KEY, [
|
|
(string) $workspaceId => (int) $tenant->getKey(),
|
|
]);
|
|
|
|
$values = alertsKpiValues(Livewire::test(AlertsKpiHeader::class));
|
|
|
|
expect($values)->toMatchArray([
|
|
'Deliveries (24h)' => '1',
|
|
'Failed (7d)' => '0',
|
|
]);
|
|
})->group('ops-ux');
|
|
|
|
it('filters KPI deliveries by tenant when context is set via Filament setTenant', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$workspaceId = (int) $tenant->workspace_id;
|
|
|
|
$rule = AlertRule::factory()->create(['workspace_id' => $workspaceId]);
|
|
$destination = AlertDestination::factory()->create(['workspace_id' => $workspaceId]);
|
|
|
|
AlertDelivery::factory()->create([
|
|
'workspace_id' => $workspaceId,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'alert_rule_id' => (int) $rule->getKey(),
|
|
'alert_destination_id' => (int) $destination->getKey(),
|
|
'status' => AlertDelivery::STATUS_SENT,
|
|
'created_at' => now()->subHour(),
|
|
]);
|
|
|
|
$otherTenant = Tenant::factory()->create(['workspace_id' => $workspaceId]);
|
|
$user->tenants()->syncWithoutDetaching([
|
|
$otherTenant->getKey() => ['role' => 'owner'],
|
|
]);
|
|
|
|
AlertDelivery::factory()->create([
|
|
'workspace_id' => $workspaceId,
|
|
'tenant_id' => (int) $otherTenant->getKey(),
|
|
'alert_rule_id' => (int) $rule->getKey(),
|
|
'alert_destination_id' => (int) $destination->getKey(),
|
|
'status' => AlertDelivery::STATUS_SENT,
|
|
'created_at' => now()->subHour(),
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
session()->put(WorkspaceContext::SESSION_KEY, $workspaceId);
|
|
|
|
$values = alertsKpiValues(Livewire::test(AlertsKpiHeader::class));
|
|
|
|
expect($values)->toMatchArray([
|
|
'Deliveries (24h)' => '1',
|
|
'Failed (7d)' => '0',
|
|
]);
|
|
})->group('ops-ux');
|
|
|
|
it('shows workspace-wide KPI counts when no tenant context is active', function (): void {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
|
|
$workspaceId = (int) $tenant->workspace_id;
|
|
|
|
$rule = AlertRule::factory()->create(['workspace_id' => $workspaceId]);
|
|
$destination = AlertDestination::factory()->create(['workspace_id' => $workspaceId]);
|
|
|
|
AlertDelivery::factory()->create([
|
|
'workspace_id' => $workspaceId,
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'alert_rule_id' => (int) $rule->getKey(),
|
|
'alert_destination_id' => (int) $destination->getKey(),
|
|
'status' => AlertDelivery::STATUS_SENT,
|
|
'created_at' => now()->subHour(),
|
|
]);
|
|
|
|
$otherTenant = Tenant::factory()->create(['workspace_id' => $workspaceId]);
|
|
$user->tenants()->syncWithoutDetaching([
|
|
$otherTenant->getKey() => ['role' => 'owner'],
|
|
]);
|
|
|
|
AlertDelivery::factory()->create([
|
|
'workspace_id' => $workspaceId,
|
|
'tenant_id' => (int) $otherTenant->getKey(),
|
|
'alert_rule_id' => (int) $rule->getKey(),
|
|
'alert_destination_id' => (int) $destination->getKey(),
|
|
'status' => AlertDelivery::STATUS_SENT,
|
|
'created_at' => now()->subHour(),
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
Filament::setTenant(null, true);
|
|
|
|
session()->put(WorkspaceContext::SESSION_KEY, $workspaceId);
|
|
|
|
$values = alertsKpiValues(Livewire::test(AlertsKpiHeader::class));
|
|
|
|
expect($values)->toMatchArray([
|
|
'Deliveries (24h)' => '2',
|
|
'Failed (7d)' => '0',
|
|
]);
|
|
})->group('ops-ux');
|
|
|
|
it('prefers the Filament tenant over remembered tenant fallback in KPI scope conflicts', function (): void {
|
|
[$user, $tenantA] = createUserWithTenant(role: 'owner');
|
|
|
|
$workspaceId = (int) $tenantA->workspace_id;
|
|
|
|
$tenantB = Tenant::factory()->create(['workspace_id' => $workspaceId]);
|
|
$user->tenants()->syncWithoutDetaching([
|
|
$tenantB->getKey() => ['role' => 'owner'],
|
|
]);
|
|
|
|
$rule = AlertRule::factory()->create(['workspace_id' => $workspaceId]);
|
|
$destination = AlertDestination::factory()->create(['workspace_id' => $workspaceId]);
|
|
|
|
AlertDelivery::factory()->create([
|
|
'workspace_id' => $workspaceId,
|
|
'tenant_id' => (int) $tenantA->getKey(),
|
|
'alert_rule_id' => (int) $rule->getKey(),
|
|
'alert_destination_id' => (int) $destination->getKey(),
|
|
'status' => AlertDelivery::STATUS_SENT,
|
|
'created_at' => now()->subHour(),
|
|
]);
|
|
|
|
AlertDelivery::factory()->create([
|
|
'workspace_id' => $workspaceId,
|
|
'tenant_id' => (int) $tenantB->getKey(),
|
|
'alert_rule_id' => (int) $rule->getKey(),
|
|
'alert_destination_id' => (int) $destination->getKey(),
|
|
'status' => AlertDelivery::STATUS_FAILED,
|
|
'created_at' => now()->subHour(),
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenantB, true);
|
|
|
|
session()->put(WorkspaceContext::SESSION_KEY, $workspaceId);
|
|
session()->put(WorkspaceContext::LAST_TENANT_IDS_SESSION_KEY, [
|
|
(string) $workspaceId => (int) $tenantA->getKey(),
|
|
]);
|
|
|
|
$values = alertsKpiValues(Livewire::test(AlertsKpiHeader::class));
|
|
|
|
expect($values)->toMatchArray([
|
|
'Deliveries (24h)' => '1',
|
|
'Failed (7d)' => '1',
|
|
]);
|
|
})->group('ops-ux');
|