Feature branch PR for Spec 114. This branch contains the merged agent session work (see merge commit on branch). Tests - `vendor/bin/sail artisan test --compact tests/Feature/System/Spec114/` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #139
74 lines
2.4 KiB
PHP
74 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\System\Pages\Security;
|
|
|
|
use App\Models\AuditLog;
|
|
use App\Models\PlatformUser;
|
|
use App\Support\Auth\PlatformCapabilities;
|
|
use Filament\Pages\Page;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Concerns\InteractsWithTable;
|
|
use Filament\Tables\Contracts\HasTable;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class AccessLogs extends Page implements HasTable
|
|
{
|
|
use InteractsWithTable;
|
|
|
|
protected static ?string $navigationLabel = 'Access logs';
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-shield-check';
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Security';
|
|
|
|
protected static ?string $slug = 'security/access-logs';
|
|
|
|
protected string $view = 'filament.system.pages.security.access-logs';
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
$user = auth('platform')->user();
|
|
|
|
return $user instanceof PlatformUser
|
|
&& $user->hasCapability(PlatformCapabilities::CONSOLE_VIEW);
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->mountInteractsWithTable();
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->defaultSort('recorded_at', 'desc')
|
|
->query(function (): Builder {
|
|
return AuditLog::query()
|
|
->where(function (Builder $query): void {
|
|
$query
|
|
->where('action', 'platform.auth.login')
|
|
->orWhere('action', 'like', 'platform.break_glass.%');
|
|
});
|
|
})
|
|
->columns([
|
|
TextColumn::make('recorded_at')
|
|
->label('Recorded')
|
|
->since(),
|
|
TextColumn::make('action')
|
|
->label('Action')
|
|
->searchable(),
|
|
TextColumn::make('status')
|
|
->badge()
|
|
->color(fn (?string $state): string => $state === 'failure' ? 'danger' : 'success'),
|
|
TextColumn::make('actor_email')
|
|
->label('Actor')
|
|
->formatStateUsing(fn (?string $state): string => $state ?: 'Unknown'),
|
|
])
|
|
->emptyStateHeading('No access logs found')
|
|
->emptyStateDescription('Platform login and break-glass events will appear here.');
|
|
}
|
|
}
|