diff --git a/CHANGELOG.md b/CHANGELOG.md index ff20f60d..de57f565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/app/Filament/Pages/RoleView.php b/app/Filament/Pages/RoleView.php new file mode 100644 index 00000000..43c9b255 --- /dev/null +++ b/app/Filament/Pages/RoleView.php @@ -0,0 +1,160 @@ +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 + */ + 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 $item + * @param array $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)); + } +} diff --git a/app/Version.php b/app/Version.php index 9ab6f4a8..eda06186 100644 --- a/app/Version.php +++ b/app/Version.php @@ -9,5 +9,5 @@ namespace App; */ final class Version { - public const VERSION = '0.54.0'; + public const VERSION = '0.55.0'; } diff --git a/resources/views/filament/pages/role-view.blade.php b/resources/views/filament/pages/role-view.blade.php new file mode 100644 index 00000000..d241c3da --- /dev/null +++ b/resources/views/filament/pages/role-view.blade.php @@ -0,0 +1,114 @@ + + + + +
+ @foreach ($roles as $item) + + @endforeach +
+
+ + @if ($role) + @if ($isAdministration) + +

„{{ $role->name }}“ hat Vollzugriff und sieht alles – Bereiche lassen sich für diese Rolle nicht ausblenden.

+
+ @else + + @if ($preview) +
+ @csrf + Als {{ $preview->name }} ansehen + Sie sehen das Portal genau so wie diese Person – oben erscheint „Zurück zu meinem Konto“. +
+ @else +

Niemand mit dieser Rolle, als den Sie das Portal ansehen dürfen. Weisen Sie die Rolle z. B. einem Testkonto zu.

+ @endif +
+ @endif + +
+ +
+ @foreach ($areas as $area) +
+ {{ $area['name'] }} + @if ($canToggle) + + @else + {{ $area['visible'] ? 'sichtbar' : 'ausgeblendet' }} + @endif +
+ @endforeach +
+
+ +
+ + @if ($menu === null) +

Automatisches Menü – es folgt den sichtbaren Bereichen.

+ @else +
+ @foreach ($menu as $item) +
+ {{ $item['label'] }} @if ($item['restricted'])· eingeschränkt@endif + {{ $item['visible'] ? 'sichtbar' : 'ausgeblendet' }} +
+ @endforeach +
+ @endif +

Menü bearbeiten – dort je Punkt „Sichtbar für“.

+
+ + +
+ @forelse ($quickLinks as $link) +
+ {{ $link['label'] }} @if ($link['restricted'])· eingeschränkt@endif + {{ $link['visible'] ? 'sichtbar' : 'ausgeblendet' }} +
+ @empty +

Keine Schnellzugriffe angelegt.

+ @endforelse +
+

Schnellzugriffe bearbeiten – dort je Eintrag „Sichtbar für“.

+
+ + + @forelse ($grants as $grant) + {{ $grant['label'] }}@if ($grant['scope']) · {{ $grant['scope'] }}@endif + @empty +

Keine besonderen Rechte – lesen, was für alle freigegeben ist.

+ @endforelse +

Rolle bearbeiten

+
+
+
+ @endif +
diff --git a/tests/Feature/Admin/RoleViewTest.php b/tests/Feature/Admin/RoleViewTest.php new file mode 100644 index 00000000..e715fe0f --- /dev/null +++ b/tests/Feature/Admin/RoleViewTest.php @@ -0,0 +1,49 @@ +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(); + } +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 5a23bb44..2d0b2b42 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -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', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 1876afa2..24c69437 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -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', diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 822eb061..b8853184 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -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(),