Implements Spec 090 (Action Surface Contract Compliance & RBAC Hardening). Highlights: - Adds/updates action surface declarations and shrinks baseline exemptions. - Standardizes Filament action grouping/order and empty-state CTAs. - Enforces RBAC UX semantics (non-member -> 404, member w/o capability -> disabled + tooltip, server-side 403). - Adds audit logging for successful side-effect actions. - Fixes Provider Connections list context so header create + row actions resolve tenant correctly. Tests (focused): - vendor/bin/sail artisan test --compact tests/Feature/090/ - vendor/bin/sail artisan test --compact tests/Feature/Guards/ActionSurfaceContractTest.php - vendor/bin/sail bin pint --dirty Livewire/Filament: - Filament v5 + Livewire v4 compliant. - No panel provider registration changes (Laravel 11+ registration remains in bootstrap/providers.php). Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #108
101 lines
3.2 KiB
PHP
101 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Filament\Resources\BackupScheduleResource\Pages\ListBackupSchedules;
|
|
use App\Filament\Resources\Workspaces\Pages\ListWorkspaces;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Models\WorkspaceMembership;
|
|
use App\Support\Workspaces\WorkspaceContext;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
final class EmptyStateCtasTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_spec090_shows_workspace_empty_state_create_cta_for_users_with_workspace_manage(): void
|
|
{
|
|
$workspace = Workspace::factory()->create([
|
|
'archived_at' => now(),
|
|
]);
|
|
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => 'owner',
|
|
]);
|
|
|
|
$user->forceFill([
|
|
'last_workspace_id' => (int) $workspace->getKey(),
|
|
])->save();
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]);
|
|
|
|
Livewire::test(ListWorkspaces::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['create'])
|
|
->assertActionVisible('create')
|
|
->assertActionEnabled('create');
|
|
}
|
|
|
|
public function test_spec090_disables_workspace_empty_state_create_cta_without_workspace_manage(): void
|
|
{
|
|
$workspace = Workspace::factory()->create([
|
|
'archived_at' => now(),
|
|
]);
|
|
|
|
$user = User::factory()->create();
|
|
|
|
WorkspaceMembership::factory()->create([
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
'user_id' => (int) $user->getKey(),
|
|
'role' => 'manager',
|
|
]);
|
|
|
|
$user->forceFill([
|
|
'last_workspace_id' => (int) $workspace->getKey(),
|
|
])->save();
|
|
|
|
$this->actingAs($user)
|
|
->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]);
|
|
|
|
Livewire::test(ListWorkspaces::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['create'])
|
|
->assertActionVisible('create')
|
|
->assertActionDisabled('create');
|
|
}
|
|
|
|
public function test_spec090_shows_backup_schedule_empty_state_create_cta_for_users_with_manage_capability(): void
|
|
{
|
|
[$user, $tenant] = createUserWithTenant(role: 'owner');
|
|
$this->actingAs($user);
|
|
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::test(ListBackupSchedules::class)
|
|
->assertTableEmptyStateActionsExistInOrder(['create'])
|
|
->assertActionVisible('create')
|
|
->assertActionEnabled('create');
|
|
}
|
|
|
|
public function test_spec090_disables_backup_schedule_empty_state_create_cta_without_manage_capability(): void
|
|
{
|
|
[$user, $tenant] = createUserWithTenant(role: 'readonly');
|
|
$this->actingAs($user);
|
|
|
|
$tenant->makeCurrent();
|
|
Filament::setTenant($tenant, true);
|
|
|
|
Livewire::test(ListBackupSchedules::class)
|
|
->assertTableEmptyStateActionsExistInOrder([])
|
|
->assertActionHidden('create');
|
|
}
|
|
}
|