## Summary - standardize filter UX across key Filament resources with shared thin filter helpers for centralized option sourcing and archived/date-range presets - add persistence, essential filters, and OperationCatalog-aligned labels across the targeted resource tables - add and extend focused Pest coverage for guards, persistence, filter behavior, scope safety, and the new Spec 126 planning artifacts ## Spec 126 - add the full Spec 126 artifact set under `specs/126-filter-ux-standardization/` - align spec, plan, research, data model, quickstart, contract, checklist, and tasks for implementation readiness ## Validation - `vendor/bin/sail bin pint --dirty --format agent` - `vendor/bin/sail artisan test --compact tests/Feature/Guards/FilamentTableStandardsGuardTest.php tests/Feature/Filament/TableStatePersistenceTest.php tests/Feature/Findings/FindingsListFiltersTest.php tests/Feature/Findings/FindingsListDefaultsTest.php tests/Feature/Alerts/AlertDeliveryDeepLinkFiltersTest.php tests/Feature/Filament/Alerts/AlertDeliveryViewerTest.php tests/Feature/Filament/OperationRunListFiltersTest.php tests/Feature/Filament/PolicyVersionListFiltersTest.php tests/Feature/Filament/RestoreRunListFiltersTest.php tests/Feature/Filament/InventoryItemListFiltersTest.php tests/Feature/Filament/BaselineProfileListFiltersTest.php tests/Feature/ProviderConnections/TenantFilterOverrideTest.php tests/Feature/Rbac/InventoryItemResourceAuthorizationTest.php tests/Feature/Filament/BaselineTenantAssignmentsRelationManagerTest.php` ## Notes - no new OperationRun lifecycle or operational workflow behavior is introduced; only existing OperationRun table filter-label alignment and related coverage are in scope - existing authorization and action-surface semantics remain unchanged Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #154
108 lines
3.6 KiB
PHP
108 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\InventoryItemResource;
|
|
use App\Filament\Resources\InventoryItemResource\Pages\ListInventoryItems;
|
|
use App\Models\InventoryItem;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use Filament\Facades\Filament;
|
|
use Livewire\Livewire;
|
|
|
|
describe('Inventory item resource authorization', function () {
|
|
it('is not visible for non-members', function () {
|
|
$user = User::factory()->create();
|
|
$tenant = Tenant::factory()->create();
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
|
|
expect(InventoryItemResource::canViewAny())->toBeFalse();
|
|
});
|
|
|
|
it('is visible for readonly members', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'readonly');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
|
|
expect(InventoryItemResource::canViewAny())->toBeTrue();
|
|
});
|
|
|
|
it('prevents viewing inventory items from other tenants', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$otherTenant = Tenant::factory()->create();
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
|
|
$record = InventoryItem::factory()->create([
|
|
'tenant_id' => $otherTenant->getKey(),
|
|
]);
|
|
|
|
expect(InventoryItemResource::canView($record))->toBeFalse();
|
|
});
|
|
|
|
it('allows viewing inventory items from the current tenant', function () {
|
|
[$user, $tenant] = createUserWithTenant(role: 'readonly');
|
|
|
|
$this->actingAs($user);
|
|
$tenant->makeCurrent();
|
|
|
|
$record = InventoryItem::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
]);
|
|
|
|
expect(InventoryItemResource::canView($record))->toBeTrue();
|
|
});
|
|
|
|
it('keeps composed persisted inventory filters scoped to the active tenant', function () {
|
|
$tenantA = Tenant::factory()->create();
|
|
[$user, $tenantA] = createUserWithTenant(tenant: $tenantA, role: 'owner');
|
|
|
|
$tenantB = Tenant::factory()->create([
|
|
'workspace_id' => (int) $tenantA->workspace_id,
|
|
]);
|
|
|
|
createUserWithTenant(tenant: $tenantB, user: $user, role: 'owner');
|
|
|
|
$tenantAFresh = InventoryItem::factory()->create([
|
|
'tenant_id' => (int) $tenantA->getKey(),
|
|
'display_name' => 'Tenant A Fresh Windows',
|
|
'platform' => 'windows',
|
|
'last_seen_at' => now(),
|
|
]);
|
|
|
|
$tenantAStale = InventoryItem::factory()->create([
|
|
'tenant_id' => (int) $tenantA->getKey(),
|
|
'display_name' => 'Tenant A Stale Windows',
|
|
'platform' => 'windows',
|
|
'last_seen_at' => now()->subDays(3),
|
|
]);
|
|
|
|
$tenantBStale = InventoryItem::factory()->create([
|
|
'tenant_id' => (int) $tenantB->getKey(),
|
|
'display_name' => 'Tenant B Stale Windows',
|
|
'platform' => 'windows',
|
|
'last_seen_at' => now()->subDays(3),
|
|
]);
|
|
|
|
$this->actingAs($user);
|
|
$tenantA->makeCurrent();
|
|
Filament::setTenant($tenantA, true);
|
|
|
|
Livewire::test(ListInventoryItems::class)
|
|
->filterTable('platform', 'windows')
|
|
->filterTable('stale', '1')
|
|
->assertCanSeeTableRecords([$tenantAStale])
|
|
->assertCanNotSeeTableRecords([$tenantAFresh, $tenantBStale]);
|
|
|
|
Livewire::test(ListInventoryItems::class)
|
|
->assertSet('tableFilters.platform.value', 'windows')
|
|
->assertSet('tableFilters.stale.value', '1')
|
|
->assertCanSeeTableRecords([$tenantAStale])
|
|
->assertCanNotSeeTableRecords([$tenantAFresh, $tenantBStale]);
|
|
});
|
|
});
|