- land the spec 192 resource, guard, browser smoke, and documentation changes - add unhandled rejection request correlation for 419 diagnostics - disable panel-wide database notification polling and cover it with focused tests
74 lines
2.6 KiB
PHP
74 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\EvidenceSnapshotResource\Pages;
|
|
|
|
use App\Filament\Resources\EvidenceSnapshotResource;
|
|
use App\Models\User;
|
|
use App\Services\Evidence\EvidenceSnapshotService;
|
|
use App\Support\Auth\Capabilities;
|
|
use App\Support\Rbac\UiEnforcement;
|
|
use Filament\Actions;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\ViewRecord;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class ViewEvidenceSnapshot extends ViewRecord
|
|
{
|
|
protected static string $resource = EvidenceSnapshotResource::class;
|
|
|
|
protected function resolveRecord(int|string $key): Model
|
|
{
|
|
return EvidenceSnapshotResource::resolveScopedRecordOrFail($key);
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
UiEnforcement::forAction(
|
|
Actions\Action::make('refresh_snapshot')
|
|
->label('Refresh evidence')
|
|
->icon('heroicon-o-arrow-path')
|
|
->color('primary')
|
|
->requiresConfirmation()
|
|
->action(function (): void {
|
|
$user = auth()->user();
|
|
|
|
if (! $user instanceof User) {
|
|
abort(403);
|
|
}
|
|
|
|
app(EvidenceSnapshotService::class)->refresh($this->record, $user);
|
|
|
|
Notification::make()->success()->title('Refresh evidence queued')->send();
|
|
}),
|
|
)
|
|
->requireCapability(Capabilities::EVIDENCE_MANAGE)
|
|
->apply(),
|
|
UiEnforcement::forAction(
|
|
Actions\Action::make('expire_snapshot')
|
|
->label('Expire snapshot')
|
|
->icon('heroicon-o-x-circle')
|
|
->color('danger')
|
|
->hidden(fn (): bool => ! EvidenceSnapshotResource::canExpireRecord($this->record))
|
|
->requiresConfirmation()
|
|
->action(function (): void {
|
|
$user = auth()->user();
|
|
|
|
if (! $user instanceof User) {
|
|
abort(403);
|
|
}
|
|
|
|
app(EvidenceSnapshotService::class)->expire($this->record, $user);
|
|
$this->refreshFormData(['status', 'expires_at']);
|
|
|
|
Notification::make()->success()->title('Snapshot expired')->send();
|
|
}),
|
|
)
|
|
->requireCapability(Capabilities::EVIDENCE_MANAGE)
|
|
->apply(),
|
|
];
|
|
}
|
|
}
|