## Summary - introduce a shared tenant-owned query and record-resolution canon for first-slice Filament resources - harden direct views, row actions, bulk actions, relation managers, and workspace-admin canonical viewers against wrong-tenant access - add registry-backed rollout metadata, search posture handling, architectural guards, and focused Pest coverage for scope parity and 404/403 semantics ## Included - Spec 150 package under `specs/150-tenant-owned-query-canon-and-wrong-tenant-guards/` - shared support classes: `TenantOwnedModelFamilies`, `TenantOwnedQueryScope`, `TenantOwnedRecordResolver` - shared Filament concern: `InteractsWithTenantOwnedRecords` - resource/page/policy hardening across findings, policies, policy versions, backup schedules, backup sets, restore runs, inventory items, and Entra groups - additional regression coverage for canonical tenant state, wrong-tenant record resolution, relation-manager congruence, and action-surface guardrails ## Validation - `vendor/bin/sail artisan test --compact` passed - full suite result: `2733 passed, 8 skipped` - formatting applied with `vendor/bin/sail bin pint --dirty --format agent` ## Notes - Livewire v4.0+ compliant via existing Filament v5 stack - provider registration remains in `bootstrap/providers.php` - globally searchable first-slice posture: Entra groups scoped; policies and policy versions explicitly disabled - destructive actions continue to use confirmation and policy authorization - no new Filament assets added; existing deployment flow remains unchanged, including `php artisan filament:assets` when registered assets are used Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #180
97 lines
4.0 KiB
PHP
97 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
function adminTenantResolverGuardedFiles(): array
|
|
{
|
|
return [
|
|
'app/Filament/Pages/BaselineCompareLanding.php',
|
|
'app/Filament/Pages/TenantDiagnostics.php',
|
|
'app/Filament/Pages/InventoryCoverage.php',
|
|
'app/Filament/Widgets/Inventory/InventoryKpiHeader.php',
|
|
'app/Filament/Pages/Monitoring/Operations.php',
|
|
'app/Filament/Pages/Operations/TenantlessOperationRunViewer.php',
|
|
'app/Filament/Widgets/Operations/OperationsKpiHeader.php',
|
|
'app/Filament/Resources/OperationRunResource.php',
|
|
'app/Filament/Resources/PolicyResource.php',
|
|
'app/Filament/Resources/BackupScheduleResource.php',
|
|
'app/Filament/Resources/BackupScheduleResource/Pages/ListBackupSchedules.php',
|
|
'app/Filament/Resources/BackupSetResource.php',
|
|
'app/Filament/Resources/BackupSetResource/Pages/ListBackupSets.php',
|
|
'app/Filament/Resources/BackupSetResource/Pages/ViewBackupSet.php',
|
|
'app/Filament/Resources/FindingResource.php',
|
|
'app/Filament/Resources/FindingResource/Pages/ListFindings.php',
|
|
'app/Filament/Resources/InventoryItemResource.php',
|
|
'app/Filament/Resources/InventoryItemResource/Pages/ListInventoryItems.php',
|
|
'app/Filament/Resources/PolicyVersionResource.php',
|
|
'app/Filament/Resources/PolicyVersionResource/Pages/ListPolicyVersions.php',
|
|
'app/Filament/Resources/ProviderConnectionResource.php',
|
|
'app/Filament/Resources/AlertDeliveryResource.php',
|
|
'app/Filament/Resources/AlertDeliveryResource/Pages/ListAlertDeliveries.php',
|
|
'app/Filament/Pages/Monitoring/AuditLog.php',
|
|
'app/Filament/Resources/ProviderConnectionResource/Pages/ListProviderConnections.php',
|
|
'app/Filament/Resources/RestoreRunResource.php',
|
|
'app/Filament/Resources/RestoreRunResource/Pages/CreateRestoreRun.php',
|
|
];
|
|
}
|
|
|
|
function adminTenantResolverExceptionFiles(): array
|
|
{
|
|
return [
|
|
'app/Filament/Pages/ChooseTenant.php',
|
|
'app/Http/Controllers/SelectTenantController.php',
|
|
'app/Support/Middleware/EnsureFilamentTenantSelected.php',
|
|
'app/Filament/Concerns/ResolvesPanelTenantContext.php',
|
|
];
|
|
}
|
|
|
|
it('keeps raw panel-native tenant reads out of canonical admin resolver surfaces', function (): void {
|
|
$forbiddenPatterns = [
|
|
'/\bFilament::getTenant\s*\(/',
|
|
'/\bTenant::current\s*\(/',
|
|
];
|
|
|
|
$violations = [];
|
|
|
|
foreach (adminTenantResolverGuardedFiles() as $relativePath) {
|
|
$contents = file_get_contents(base_path($relativePath));
|
|
|
|
expect($contents)->not->toBeFalse();
|
|
|
|
foreach ($forbiddenPatterns as $pattern) {
|
|
if (preg_match($pattern, (string) $contents) === 1) {
|
|
$violations[] = $relativePath;
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
expect($violations)
|
|
->toBeEmpty('Canonical admin surfaces must delegate tenant resolution to OperateHubShell. Offenders: '.implode(', ', $violations));
|
|
});
|
|
|
|
it('documents the approved panel-native exception inventory', function (): void {
|
|
$notes = file_get_contents(base_path('docs/research/admin-canonical-tenant-rollout.md'));
|
|
|
|
expect($notes)->not->toBeFalse();
|
|
|
|
foreach (adminTenantResolverExceptionFiles() as $relativePath) {
|
|
expect($notes)->toContain($relativePath);
|
|
}
|
|
});
|
|
|
|
it('keeps the shared panel resolver explicit about admin and tenant-panel resolution', function (): void {
|
|
$resolverContents = file_get_contents(base_path('app/Filament/Concerns/ResolvesPanelTenantContext.php'));
|
|
$contents = file_get_contents(base_path('app/Filament/Resources/EntraGroupResource.php'));
|
|
|
|
expect($resolverContents)->not->toBeFalse()
|
|
->and($resolverContents)->toContain('tenantOwnedPanelContext(request())')
|
|
->and($resolverContents)->toContain('Tenant::current()');
|
|
|
|
expect($contents)->not->toBeFalse()
|
|
->and($contents)->toContain('use ResolvesPanelTenantContext;')
|
|
->and($contents)->not->toContain('activeEntitledTenant(request())')
|
|
->and($contents)->not->toContain('Tenant::current()');
|
|
});
|