Amends the constitution to clarify admin vs tenant-context vs workspace-context, and codifies data ownership boundaries.
Changes:
- RBAC Context plane clarification:
- Tenant/Admin plane: `/admin`
- Tenant-context routes: `/admin/t/{tenant}/...` (tenant-scoped)
- Workspace-context canonical routes under `/admin/...` must still enforce entitlement before revealing tenant-owned records
- Adds SCOPE-001 (Scope & Ownership Clarification) under Tenant Isolation.
- Extends RBAC-UX-007 with workspace-context Global Search rules.
- Adds SCOPE-002 (Spec Scope Fields) to Filament Action Surface Contract DoD gates.
- Version bump: 1.8.2, Last Amended: 2026-02-14.
Propagation:
- Updates SpecKit templates to include Spec Scope Fields and updated RBAC plane wording.
Files:
- `.specify/memory/constitution.md`
- `.specify/templates/spec-template.md`
- `.specify/templates/plan-template.md`
- `.specify/templates/tasks-template.md`
Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #111
113 lines
3.7 KiB
PHP
113 lines
3.7 KiB
PHP
<?php
|
|
|
|
use App\Filament\Resources\BackupSetResource;
|
|
use App\Filament\Resources\BackupSetResource\Pages\ListBackupSets;
|
|
use App\Models\BackupSet;
|
|
use App\Models\Tenant;
|
|
use App\Support\Auth\UiTooltips;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Livewire\Livewire;
|
|
|
|
function getTableEmptyStateAction($component, string $name): ?\Filament\Actions\Action
|
|
{
|
|
foreach ($component->instance()->getTable()->getEmptyStateActions() as $action) {
|
|
if ($action instanceof \Filament\Actions\Action && $action->getName() === $name) {
|
|
return $action;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
Http::preventStrayRequests();
|
|
});
|
|
|
|
test('non-members are denied access to BackupSet tenant routes (404)', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$otherTenant = Tenant::factory()->create();
|
|
|
|
[$user] = createUserWithTenant($otherTenant, role: 'owner');
|
|
|
|
$this->actingAs($user)
|
|
->get(BackupSetResource::getUrl('index', tenant: $tenant))
|
|
->assertStatus(404);
|
|
});
|
|
|
|
test('members without capability see BackupSet actions disabled with standard tooltip and cannot execute', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
[$user] = createUserWithTenant($tenant, role: 'readonly');
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'status' => 'completed',
|
|
'deleted_at' => null,
|
|
]);
|
|
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(ListBackupSets::class)
|
|
->assertTableActionDisabled('archive', $backupSet)
|
|
->assertTableActionExists('archive', fn ($action): bool => $action->getTooltip() === UiTooltips::insufficientPermission(), $backupSet)
|
|
->callTableAction('archive', $backupSet);
|
|
|
|
expect($backupSet->fresh()->trashed())->toBeFalse();
|
|
});
|
|
|
|
test('members with capability can execute BackupSet actions', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
[$user] = createUserWithTenant($tenant, role: 'owner');
|
|
|
|
$backupSet = BackupSet::factory()->create([
|
|
'tenant_id' => $tenant->getKey(),
|
|
'status' => 'completed',
|
|
'deleted_at' => null,
|
|
]);
|
|
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::actingAs($user)
|
|
->test(ListBackupSets::class)
|
|
->assertTableActionEnabled('archive', $backupSet)
|
|
->callTableAction('archive', $backupSet);
|
|
|
|
expect($backupSet->fresh()->trashed())->toBeTrue();
|
|
});
|
|
|
|
test('backup sets list shows empty state create action enabled for members with sync capability', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
[$user] = createUserWithTenant($tenant, role: 'owner');
|
|
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$component = Livewire::actingAs($user)
|
|
->test(ListBackupSets::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['create']);
|
|
|
|
$action = getTableEmptyStateAction($component, 'create');
|
|
expect($action)->not->toBeNull();
|
|
expect($action->isVisible())->toBeTrue();
|
|
expect($action->isDisabled())->toBeFalse();
|
|
});
|
|
|
|
test('backup sets list shows empty state create action disabled for members without sync capability', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
[$user] = createUserWithTenant($tenant, role: 'readonly');
|
|
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$component = Livewire::actingAs($user)
|
|
->test(ListBackupSets::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['create']);
|
|
|
|
$action = getTableEmptyStateAction($component, 'create');
|
|
expect($action)->not->toBeNull();
|
|
expect($action->isVisible())->toBeTrue();
|
|
expect($action->isDisabled())->toBeTrue();
|
|
});
|