Loheide-eu-mitarbeiterplatt.../app/Filament/Resources/Users/Tables/UsersTable.php
Friederich Loheide 546c94db1c
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 4m47s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m40s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m51s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m1s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m45s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m36s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m21s
Profil zeigt geschriebene Beiträge, Als Person anmelden (0.27.1)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 10:03:27 +00:00

68 lines
3.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Filament\Resources\Users\Tables;
use App\Models\User;
use App\Support\Impersonation;
use Filament\Actions\Action;
use Filament\Actions\EditAction;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
class UsersTable
{
public static function configure(Table $table): Table
{
return $table
->defaultSort('name')
->columns([
ImageColumn::make('avatar')
->label('')
->circular()
->state(fn (User $record) => $record->avatarUrl(96))
->width(40),
TextColumn::make('name')->label('Name')->searchable()->sortable(),
TextColumn::make('email')->label('E-Mail')->searchable()->toggleable(),
TextColumn::make('job_title')->label('Funktion')->toggleable(),
TextColumn::make('department')->label('Abteilung')->sortable()->toggleable(),
TextColumn::make('location')->label('Standort')->sortable()->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('roles.name')->label('Rollen')->badge()->color('gray'),
IconColumn::make('is_active')->label('Aktiv')->boolean(),
TextColumn::make('last_login_at')
->label('Letzte Anmeldung')
->since()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
TernaryFilter::make('is_active')->label('Aktiv'),
SelectFilter::make('roles')->label('Rolle')->relationship('roles', 'name'),
SelectFilter::make('department')
->label('Abteilung')
->options(fn () => User::query()->whereNotNull('department')->distinct()->orderBy('department')->pluck('department', 'department')->all()),
])
->recordActions([
Action::make('impersonate')
->label('Als Person anmelden')
->icon(Heroicon::OutlinedEye)
->color('gray')
->iconButton()
->tooltip('Als diese Person anmelden – Ansicht und Rechte prüfen')
->visible(fn (User $record) => app(Impersonation::class)->canImpersonate(auth()->user(), $record))
->requiresConfirmation()
->modalHeading(fn (User $record) => 'Als '.$record->name.' anmelden?')
->modalDescription('Sie sehen das Portal mit den Rechten dieser Person. Alles, was Sie tun, geschieht in ihrem Namen – der Wechsel wird protokolliert. Zurück geht es über das Band unten.')
->modalSubmitActionLabel('Anmelden')
->action(function (User $record, $livewire) {
app(Impersonation::class)->start(auth()->user(), $record);
$livewire->redirect('/');
}),
EditAction::make(),
]);
}
}