Was sieht wer? (0.55.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 13m13s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 13m34s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 9m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 10m42s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 12m16s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 12m54s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 11m10s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 10m38s

Admin-Seite je Rolle: Bereiche direkt ein-/ausblenden, Menü, Schnellzugriffe,
Rechte und „Als … ansehen“.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-30 14:51:37 +00:00
parent eef5cec357
commit 027caecf8f
8 changed files with 334 additions and 3 deletions

View file

@ -4,6 +4,12 @@ Neueste Version oben. Jeder Abschnitt beginnt mit `## MAJOR.MINOR.PATCH` und
enthält kurze Stichpunkte für Anwenderinnen und Anwender – keine Commit-Texte.
Der Self-Updater zeigt diese Abschnitte bei neuen Versionen an.
## 0.55.0 – Was sieht wer?
- Neu unter Benutzer & Rechte: **„Was sieht wer?“** – eine Rolle wählen (z. B. Klienten) und auf einen Blick sehen, welche Bereiche, Menüpunkte und Schnellzugriffe sie sieht und welche Rechte sie hat
- Bereiche lassen sich dort **direkt ein- und ausblenden**; ausgeblendet verschwinden Menüpunkt, Seiten, Startseiten-Kacheln, Suchtreffer, Feed und Aufgaben des Bereichs
- **„Als … ansehen“**: per Klick das Portal mit den Augen einer Person dieser Rolle sehen (über „Zurück zu meinem Konto“ wieder zurück)
## 0.54.0 – Feed in der Mitarbeiter-App
- In der Oberfläche „Mitarbeiter-App“ steht in der Mitte der Startseite jetzt ein **Feed**: Neuigkeiten als Beiträge ihrer Autorinnen und Autoren, **„Neu im Team“** mit Foto und Link zum Profil, neu eingetragene Termine, neue Umfragen und – mit dem Plugin Gruppen ab 1.3.0 – Beiträge aus den eigenen Gruppen. Ältere Beiträge lassen sich nachladen

View file

@ -0,0 +1,160 @@
<?php
namespace App\Filament\Pages;
use App\Models\Role;
use App\Models\User;
use App\Plugins\PluginAccess;
use App\Plugins\PluginManager;
use App\Plugins\PluginManifest;
use App\Support\Abilities;
use App\Support\Audit;
use App\Support\Impersonation;
use App\Support\Navigation;
use App\Support\QuickLinks;
use App\Support\Settings;
use BackedEnum;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
use UnitEnum;
/**
* „Was sieht wer?“ – eine Rolle (z. B. Klienten) auf einen Blick: welche Bereiche sie
* sieht (hier direkt umschaltbar), welche Menüpunkte und Schnellzugriffe, welche Rechte –
* und per Klick das Portal mit den Augen einer Person dieser Rolle.
*/
class RoleView extends Page
{
protected string $view = 'filament.pages.role-view';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedEye;
protected static string|UnitEnum|null $navigationGroup = 'Benutzer & Rechte';
protected static ?int $navigationSort = 4;
protected static ?string $title = 'Was sieht wer?';
protected static ?string $slug = 'was-sieht-wer';
/** Anmeldeverfahren und Importe lassen sich nicht je Rolle sperren */
private const WITHOUT_ACCESS = ['ldap', 'oidc', 'saml', 'wordpress-import'];
public ?int $roleId = null;
public static function canAccess(): bool
{
return auth()->user()?->can('roles.manage') ?? false;
}
public function mount(): void
{
$this->roleId = (int) request()->query('rolle') ?: Role::query()->where('is_system', false)->orderBy('name')->value('id');
}
public function selectRole(int $id): void
{
$this->roleId = $id;
}
/** Bereich für die gewählte Rolle ein- oder ausblenden */
public function toggleArea(string $slug): void
{
abort_unless(static::canAccess() && auth()->user()->can('plugins.manage'), 403);
$role = Role::query()->findOrFail($this->roleId);
abort_if($role->isAdministration() || in_array($slug, self::WITHOUT_ACCESS, true), 422);
$access = app(PluginAccess::class);
$excluded = $access->excludedRoles($slug);
$hide = ! in_array($role->id, $excluded, true);
$roles = $hide ? [...$excluded, $role->id] : array_values(array_diff($excluded, [$role->id]));
$access->exclude($slug, $roles);
Audit::log('plugin.access', ['plugin' => $slug, 'excluded_roles' => $roles]);
Notification::make()->success()
->title($hide ? 'Für „'.$role->name.'“ ausgeblendet' : 'Für „'.$role->name.'“ sichtbar')
->body($hide ? 'Menüpunkt, Seiten, Startseiten-Kacheln, Suchtreffer, Feed und Aufgaben dieses Bereichs entfallen für die Rolle.' : null)
->send();
}
/**
* @return array<string, mixed>
*/
protected function getViewData(): array
{
$roles = Role::query()->withCount('users')->orderByDesc('is_system')->orderBy('name')->get();
$role = $roles->firstWhere('id', $this->roleId);
if (! $role) {
return ['roles' => $roles, 'role' => null];
}
$plugins = app(PluginManager::class);
$access = app(PluginAccess::class);
$abilities = app(Abilities::class)->all();
$modules = app(Navigation::class)->modules();
$menu = app(Settings::class)->get(Navigation::MENU_SETTING);
$visibleFor = fn (array $roles) => $roles === [] || in_array($role->id, array_map('intval', $roles), true);
$grants = $role->grants()->get();
return [
'roles' => $roles,
'role' => $role,
'isAdministration' => $role->isAdministration(),
'canToggle' => auth()->user()->can('plugins.manage') && ! $role->isAdministration(),
'areas' => collect($plugins->all())
->filter(fn (PluginManifest $m) => $plugins->isEnabled($m->slug) && ! in_array($m->slug, self::WITHOUT_ACCESS, true))
->map(fn (PluginManifest $m) => [
'slug' => $m->slug,
'name' => $m->name,
'core' => $m->core,
'visible' => ! in_array($role->id, $access->excludedRoles($m->slug), true),
])->sortBy('name')->values(),
'menu' => is_array($menu) && $menu !== [] ? collect($menu)->map(fn (array $item) => [
'label' => $this->menuLabel($item, $modules),
'visible' => $visibleFor((array) ($item['roles'] ?? []))
&& ! in_array($role->id, $access->excludedRoles((string) ($item['module'] ?? '')), true),
'restricted' => ($item['roles'] ?? []) !== [],
])->all() : null,
'quickLinks' => collect(app(QuickLinks::class)->all())->map(fn (array $link) => [
'label' => $link['label'],
'visible' => $visibleFor($link['roles']),
'restricted' => $link['roles'] !== [],
])->all(),
'grants' => $grants->map(fn ($grant) => [
'label' => $grant->ability === '*' ? 'Vollzugriff' : ($abilities[$grant->ability]['label'] ?? $grant->ability),
'scope' => $grant->resource_type ? 'für einzelne Objekte' : null,
])->unique('label')->values(),
'preview' => $this->previewPerson($role),
];
}
/**
* @param array<string, mixed> $item
* @param array<string, string> $modules
*/
private function menuLabel(array $item, array $modules): string
{
$type = (string) ($item['type'] ?? '');
return match (true) {
filled($item['label'] ?? null) => (string) $item['label'],
$type === 'module' => $modules[$item['module'] ?? ''] ?? (string) ($item['module'] ?? 'Bereich'),
in_array($type, ['link', 'group'], true) => $type === 'link' ? 'Link' : 'Gruppe',
default => (string) (app(Navigation::class)->sourceOptions($type)[$item['target'] ?? ''] ?? $type),
};
}
/** Eine Person dieser Rolle, als die die Administration das Portal ansehen darf */
private function previewPerson(Role $role): ?User
{
$me = auth()->user();
$impersonation = app(Impersonation::class);
return $role->users()->where('is_active', true)->whereKeyNot($me->getKey())->orderBy('users.id')->limit(20)->get()
->first(fn (User $user) => $impersonation->canImpersonate($me, $user));
}
}

View file

@ -9,5 +9,5 @@ namespace App;
*/
final class Version
{
public const VERSION = '0.54.0';
public const VERSION = '0.55.0';
}

View file

@ -0,0 +1,114 @@
<x-filament-panels::page>
<style>
.ih-roles { display: flex; flex-wrap: wrap; gap: .5rem; }
.ih-role { padding: .375rem .75rem; border-radius: 999px; font-size: .875rem; border: 1px solid rgb(229 231 235); background: white; }
.ih-role[aria-pressed="true"] { background: var(--primary-600, #0f4c5c); border-color: transparent; color: white; }
.ih-role small { opacity: .7; }
.ih-grid { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); align-items: start; }
.ih-list { display: grid; gap: .125rem; }
.ih-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-top: 1px solid rgb(243 244 246); font-size: .875rem; }
.ih-row:first-child { border-top: 0; }
.ih-state { font-size: .75rem; font-weight: 600; border-radius: 999px; padding: .125rem .5rem; white-space: nowrap; }
.ih-on { background: rgb(220 252 231); color: rgb(22 101 52); }
.ih-off { background: rgb(243 244 246); color: rgb(107 114 128); }
.ih-muted { color: rgb(107 114 128); font-size: .875rem; }
.ih-switch { display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; background: none; border: 0; padding: 0; font: inherit; }
.dark .ih-role { background: rgb(17 24 39); border-color: rgb(55 65 81); }
.dark .ih-row { border-color: rgb(55 65 81); }
.dark .ih-off { background: rgb(31 41 55); color: rgb(156 163 175); }
.dark .ih-on { background: rgb(20 83 45); color: rgb(187 247 208); }
.dark .ih-muted { color: rgb(156 163 175); }
</style>
<x-filament::section heading="Rolle wählen" description="Was sieht eine Person mit dieser Rolle im Portal? Bereiche lassen sich hier direkt ein- und ausblenden.">
<div class="ih-roles">
@foreach ($roles as $item)
<button type="button" class="ih-role" aria-pressed="{{ $role && $role->id === $item->id ? 'true' : 'false' }}" wire:click="selectRole({{ $item->id }})">
{{ $item->name }} <small>· {{ $item->users_count }}</small>
</button>
@endforeach
</div>
</x-filament::section>
@if ($role)
@if ($isAdministration)
<x-filament::section>
<p class="ih-muted">„{{ $role->name }}“ hat Vollzugriff und sieht alles – Bereiche lassen sich für diese Rolle nicht ausblenden.</p>
</x-filament::section>
@else
<x-filament::section :heading="'Portal ansehen als „'.$role->name.'“'" compact>
@if ($preview)
<form method="POST" action="{{ url('/anmelden-als/'.$preview->id) }}" style="display: flex; align-items: center; gap: 1rem; flex-wrap: wrap">
@csrf
<x-filament::button type="submit" icon="heroicon-o-eye">Als {{ $preview->name }} ansehen</x-filament::button>
<span class="ih-muted">Sie sehen das Portal genau so wie diese Person – oben erscheint „Zurück zu meinem Konto“.</span>
</form>
@else
<p class="ih-muted">Niemand mit dieser Rolle, als den Sie das Portal ansehen dürfen. Weisen Sie die Rolle z. B. einem Testkonto zu.</p>
@endif
</x-filament::section>
@endif
<div class="ih-grid">
<x-filament::section heading="Bereiche" :description="$canToggle ? 'Ausgeblendete Bereiche verschwinden ganz: Menüpunkt, Seiten, Kacheln, Suche, Feed und Aufgaben.' : null">
<div class="ih-list">
@foreach ($areas as $area)
<div class="ih-row">
<span>{{ $area['name'] }}</span>
@if ($canToggle)
<button type="button" class="ih-switch" wire:click="toggleArea('{{ $area['slug'] }}')" wire:loading.attr="disabled"
aria-label="{{ $area['name'] }} {{ $area['visible'] ? 'ausblenden' : 'einblenden' }}">
<span class="ih-state {{ $area['visible'] ? 'ih-on' : 'ih-off' }}">{{ $area['visible'] ? 'sichtbar' : 'ausgeblendet' }}</span>
<x-filament::icon :icon="$area['visible'] ? 'heroicon-o-eye-slash' : 'heroicon-o-eye'" style="width: 1.1rem; height: 1.1rem; color: rgb(107 114 128)" />
</button>
@else
<span class="ih-state {{ $area['visible'] ? 'ih-on' : 'ih-off' }}">{{ $area['visible'] ? 'sichtbar' : 'ausgeblendet' }}</span>
@endif
</div>
@endforeach
</div>
</x-filament::section>
<div style="display: grid; gap: 1.5rem">
<x-filament::section heading="Menü">
@if ($menu === null)
<p class="ih-muted">Automatisches Menü – es folgt den sichtbaren Bereichen.</p>
@else
<div class="ih-list">
@foreach ($menu as $item)
<div class="ih-row">
<span>{{ $item['label'] }} @if ($item['restricted'])<span class="ih-muted">· eingeschränkt</span>@endif</span>
<span class="ih-state {{ $item['visible'] ? 'ih-on' : 'ih-off' }}">{{ $item['visible'] ? 'sichtbar' : 'ausgeblendet' }}</span>
</div>
@endforeach
</div>
@endif
<p class="ih-muted" style="margin-top: .75rem"><a href="{{ \App\Filament\Pages\MenuSettings::getUrl() }}" style="text-decoration: underline">Menü bearbeiten</a> – dort je Punkt „Sichtbar für“.</p>
</x-filament::section>
<x-filament::section heading="Schnellzugriffe">
<div class="ih-list">
@forelse ($quickLinks as $link)
<div class="ih-row">
<span>{{ $link['label'] }} @if ($link['restricted'])<span class="ih-muted">· eingeschränkt</span>@endif</span>
<span class="ih-state {{ $link['visible'] ? 'ih-on' : 'ih-off' }}">{{ $link['visible'] ? 'sichtbar' : 'ausgeblendet' }}</span>
</div>
@empty
<p class="ih-muted">Keine Schnellzugriffe angelegt.</p>
@endforelse
</div>
<p class="ih-muted" style="margin-top: .75rem"><a href="{{ \App\Filament\Pages\QuickLinksSettings::getUrl() }}" style="text-decoration: underline">Schnellzugriffe bearbeiten</a> – dort je Eintrag „Sichtbar für“.</p>
</x-filament::section>
<x-filament::section heading="Rechte der Rolle">
@forelse ($grants as $grant)
<x-filament::badge color="gray" style="margin: 0 .375rem .375rem 0; display: inline-flex">{{ $grant['label'] }}@if ($grant['scope']) · {{ $grant['scope'] }}@endif</x-filament::badge>
@empty
<p class="ih-muted">Keine besonderen Rechte – lesen, was für alle freigegeben ist.</p>
@endforelse
<p class="ih-muted" style="margin-top: .75rem"><a href="{{ \App\Filament\Resources\Roles\RoleResource::getUrl('edit', ['record' => $role]) }}" style="text-decoration: underline">Rolle bearbeiten</a></p>
</x-filament::section>
</div>
</div>
@endif
</x-filament-panels::page>

View file

@ -0,0 +1,49 @@
<?php
namespace Tests\Feature\Admin;
use App\Filament\Pages\RoleView;
use App\Models\Role;
use App\Models\User;
use App\Plugins\PluginAccess;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class RoleViewTest extends TestCase
{
use RefreshDatabase;
public function test_areas_can_be_hidden_and_shown_per_role(): void
{
$admin = User::factory()->admin()->create();
$clients = Role::query()->create(['name' => 'Klienten']);
$client = User::factory()->withRoles([$clients])->create(['first_name' => 'Jonas', 'last_name' => 'Keller']);
$this->actingAs($admin);
Livewire::test(RoleView::class)
->call('selectRole', $clients->id)
->assertSee('Klienten')
->assertSee('Als Jonas Keller ansehen')
->call('toggleArea', 'qm');
$this->assertContains($clients->id, app(PluginAccess::class)->excludedRoles('qm'));
$this->actingAs($client)->get('/qm')->assertForbidden();
$this->actingAs($admin);
Livewire::test(RoleView::class)->call('selectRole', $clients->id)->call('toggleArea', 'qm');
$this->assertNotContains($clients->id, app(PluginAccess::class)->excludedRoles('qm'));
}
public function test_login_methods_cannot_be_hidden_and_page_is_for_role_managers(): void
{
$admin = User::factory()->admin()->create();
$clients = Role::query()->create(['name' => 'Klienten']);
$this->actingAs($admin);
Livewire::test(RoleView::class)->call('selectRole', $clients->id)->call('toggleArea', 'oidc')->assertStatus(422);
$this->actingAs(User::factory()->create())->get('/admin/was-sieht-wer')->assertForbidden();
$this->actingAs($admin)->get('/admin/was-sieht-wer')->assertOk();
}
}

View file

@ -55,6 +55,7 @@ return array(
'App\\Filament\\Pages\\PermissionChecker' => $baseDir . '/app/Filament/Pages/PermissionChecker.php',
'App\\Filament\\Pages\\Plugins' => $baseDir . '/app/Filament/Pages/Plugins.php',
'App\\Filament\\Pages\\QuickLinksSettings' => $baseDir . '/app/Filament/Pages/QuickLinksSettings.php',
'App\\Filament\\Pages\\RoleView' => $baseDir . '/app/Filament/Pages/RoleView.php',
'App\\Filament\\Pages\\SystemHealth' => $baseDir . '/app/Filament/Pages/SystemHealth.php',
'App\\Filament\\Pages\\Updates' => $baseDir . '/app/Filament/Pages/Updates.php',
'App\\Filament\\Resources\\DashboardTiles\\DashboardTileResource' => $baseDir . '/app/Filament/Resources/DashboardTiles/DashboardTileResource.php',

View file

@ -857,6 +857,7 @@ class ComposerStaticInit7be5f0fc2523def46ad071c4f7cbcb0e
'App\\Filament\\Pages\\PermissionChecker' => __DIR__ . '/../..' . '/app/Filament/Pages/PermissionChecker.php',
'App\\Filament\\Pages\\Plugins' => __DIR__ . '/../..' . '/app/Filament/Pages/Plugins.php',
'App\\Filament\\Pages\\QuickLinksSettings' => __DIR__ . '/../..' . '/app/Filament/Pages/QuickLinksSettings.php',
'App\\Filament\\Pages\\RoleView' => __DIR__ . '/../..' . '/app/Filament/Pages/RoleView.php',
'App\\Filament\\Pages\\SystemHealth' => __DIR__ . '/../..' . '/app/Filament/Pages/SystemHealth.php',
'App\\Filament\\Pages\\Updates' => __DIR__ . '/../..' . '/app/Filament/Pages/Updates.php',
'App\\Filament\\Resources\\DashboardTiles\\DashboardTileResource' => __DIR__ . '/../..' . '/app/Filament/Resources/DashboardTiles/DashboardTileResource.php',

View file

@ -3,7 +3,7 @@
'name' => 'inhaus/inhaus',
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => 'ab76b65aff224ab4572aa5c878dacc38aecac4bf',
'reference' => 'eef5cec3574004b56957147741f609d04c668516',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@ -550,7 +550,7 @@
'inhaus/inhaus' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => 'ab76b65aff224ab4572aa5c878dacc38aecac4bf',
'reference' => 'eef5cec3574004b56957147741f609d04c668516',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),