Profil zeigt geschriebene Beiträge, Als Person anmelden (0.27.1)
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
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
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1469f50401
commit
546c94db1c
127 changed files with 643 additions and 337 deletions
|
|
@ -3,7 +3,10 @@
|
|||
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;
|
||||
|
|
@ -44,6 +47,21 @@ class UsersTable
|
|||
->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(),
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
26
app/Http/Controllers/ImpersonationController.php
Normal file
26
app/Http/Controllers/ImpersonationController.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Support\Impersonation;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ImpersonationController extends Controller
|
||||
{
|
||||
public function start(Request $request, User $user, Impersonation $impersonation): RedirectResponse
|
||||
{
|
||||
abort_unless($impersonation->canImpersonate($request->user(), $user), 403);
|
||||
$impersonation->start($request->user(), $user);
|
||||
|
||||
return redirect('/')->with('status', 'Sie sehen das Portal jetzt als '.$user->name.'.');
|
||||
}
|
||||
|
||||
public function stop(Impersonation $impersonation): RedirectResponse
|
||||
{
|
||||
$impersonation->stop();
|
||||
|
||||
return redirect('/admin/benutzer');
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ namespace App\Http\Middleware;
|
|||
|
||||
use App\Push\WebPush;
|
||||
use App\Support\Branding;
|
||||
use App\Support\Impersonation;
|
||||
use App\Support\Navigation;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Middleware;
|
||||
|
|
@ -41,6 +42,7 @@ class HandleInertiaRequests extends Middleware
|
|||
] : null,
|
||||
],
|
||||
'navigation' => fn () => $user ? $this->navigation->items($request, $user) : [],
|
||||
'impersonation' => fn () => $user && app(Impersonation::class)->active() ? ['name' => $user->name, 'by' => app(Impersonation::class)->impersonator()?->name] : null,
|
||||
'notifications' => fn () => $user ? ['unread' => $user->unreadNotifications()->count()] : null,
|
||||
// Web-Push: öffentlicher Schlüssel für dieses Portal
|
||||
'push' => fn () => $user && WebPush::supported() ? ['key' => app(WebPush::class)->publicKey()] : null,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use Filament\Panel;
|
|||
use Filament\PanelProvider;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\View\PanelsRenderHook;
|
||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestForgery;
|
||||
|
|
@ -53,6 +54,7 @@ class AdminPanelProvider extends PanelProvider
|
|||
])
|
||||
->navigationGroups(['Inhalte', 'Qualitätsmanagement', 'Benutzer & Rechte', 'Portal', 'System', 'Hilfe'])
|
||||
->databaseNotifications()
|
||||
->renderHook(PanelsRenderHook::BODY_END, fn () => view('filament.impersonation-banner'))
|
||||
->userMenuItems([
|
||||
Action::make('feedback')
|
||||
->label('Rückmeldung geben')
|
||||
|
|
|
|||
74
app/Support/Impersonation.php
Normal file
74
app/Support/Impersonation.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* „Als Benutzer anmelden“: Die Administration sieht das Portal mit den Rechten einer
|
||||
* anderen Person, um Ansicht und Rechte zu prüfen. Jeder Wechsel wird protokolliert;
|
||||
* zurück geht es über das Band oben („Zurück zu meinem Konto“).
|
||||
*/
|
||||
class Impersonation
|
||||
{
|
||||
public const SESSION = 'impersonator_id';
|
||||
|
||||
public function canImpersonate(?User $actor, User $target): bool
|
||||
{
|
||||
return $actor !== null
|
||||
&& ! $this->active()
|
||||
&& $actor->can('users.manage')
|
||||
&& $target->is_active
|
||||
&& ! $target->is($actor)
|
||||
// Vollzugriff nur, wer selbst Vollzugriff hat
|
||||
&& (! $target->permissions()->isSuperuser() || $actor->permissions()->isSuperuser());
|
||||
}
|
||||
|
||||
public function start(User $actor, User $target): void
|
||||
{
|
||||
if (! $this->canImpersonate($actor, $target)) {
|
||||
throw new RuntimeException('Anmelden als diese Person ist nicht erlaubt.');
|
||||
}
|
||||
|
||||
Audit::log('user.impersonation_started', ['target' => $target->id, 'name' => $target->name]);
|
||||
$this->switchTo($target);
|
||||
session()->put(self::SESSION, $actor->id);
|
||||
}
|
||||
|
||||
public function stop(): ?User
|
||||
{
|
||||
$original = $this->impersonator();
|
||||
|
||||
if (! $original) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$target = Auth::user();
|
||||
session()->forget(self::SESSION);
|
||||
$this->switchTo($original);
|
||||
Audit::log('user.impersonation_stopped', ['target' => $target?->id, 'name' => $target?->name]);
|
||||
|
||||
return $original;
|
||||
}
|
||||
|
||||
public function active(): bool
|
||||
{
|
||||
return session()->has(self::SESSION);
|
||||
}
|
||||
|
||||
public function impersonator(): ?User
|
||||
{
|
||||
$id = session()->get(self::SESSION);
|
||||
|
||||
return $id ? User::query()->find($id) : null;
|
||||
}
|
||||
|
||||
private function switchTo(User $user): void
|
||||
{
|
||||
Auth::guard('web')->login($user);
|
||||
// Sitzungsprüfung (Passwort-Fingerabdruck) auf die neue Person umstellen
|
||||
session()->forget('password_hash_web');
|
||||
}
|
||||
}
|
||||
|
|
@ -9,5 +9,5 @@ namespace App;
|
|||
*/
|
||||
final class Version
|
||||
{
|
||||
public const VERSION = '0.27.0';
|
||||
public const VERSION = '0.27.1';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue