Loheide-eu-mitarbeiterplatt.../app/Http/Middleware/HandleInertiaRequests.php
Friederich Loheide 4d58364104
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.3 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.4 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.4 (pull_request) Has been skipped
CI / Browser-Tests (pull_request) Successful in 14m21s
CI / PHP 8.3 / mysql:8.4-1 (pull_request) Successful in 19m7s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 5m20s
CI / Build-Artefakte aktuell (pull_request) Successful in 5m46s
Frag das Portal als schwebende Blase, Suchliste im Bild (0.65.0)
- AskBubble unten rechts (abschaltbar), Gespräch bleibt beim Seitenwechsel
- Antwortanzeige als gemeinsame Komponente AskAnswer
- Trefferliste der Kopfzeilen-Suche in der App-Oberfläche linksbündig
- CI: optionale Kern-Plugins für Browser-Tests einschalten, Suchtest mit Demo-Inhalt

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-07 19:02:18 +00:00

93 lines
3.9 KiB
PHP
Raw 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\Http\Middleware;
use App\Ask\AskPortal;
use App\Layout\Footer;
use App\Layout\HeaderItems;
use App\Models\User;
use App\Push\WebPush;
use App\Support\Branding;
use App\Support\Impersonation;
use App\Support\Navigation;
use App\Support\QuickLinks;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Middleware;
class HandleInertiaRequests extends Middleware
{
protected $rootView = 'app';
public function __construct(
private readonly Branding $branding,
private readonly Navigation $navigation,
) {}
/**
* @return array<string, mixed>
*/
public function share(Request $request): array
{
$user = $request->user();
return [
...parent::share($request),
'branding' => $this->branding->toArray(),
// In der App eingebettet: ohne Kopf- und Fußzeile des Portals
'embedded' => (bool) $request->session()->get('embedded', false),
// Frei gestaltete Fußzeile – einmal geladen, dann im Browser behalten (bis zur nächsten Veröffentlichung)
'footerContent' => $user ? $this->footer($request, $user) : null,
// Symbole von Plugins in der Kopfzeile (z. B. Nachrichten)
'headerItems' => $user ? fn () => app(HeaderItems::class)->resolve($user) : [],
'auth' => [
'user' => $user ? [
'id' => $user->id,
'name' => $user->name,
'email' => $user->email,
'initials' => $user->initials,
'job_title' => $user->job_title,
'avatar_url' => $user->avatarUrl(96),
'cover_url' => $user->coverUrl(),
'theme' => $user->theme,
'can_admin' => $user->canAccessAdmin(),
// Einfache Ansicht (Rolle mit „Einfache Ansicht“, z. B. Klienten)
'simple' => $user->usesSimpleUi(),
] : null,
],
'navigation' => fn () => $user ? $this->navigation->items($request, $user) : [],
// Schnellzugriffe für „Anwendungen“ in der Kopfzeile (je Person gefiltert)
'apps' => fn () => $user ? app(QuickLinks::class)->forUser($user) : [],
// „Frag das Portal“ eingeschaltet (KI eingerichtet)?
'ask' => fn () => $user && app(AskPortal::class)->enabled() ? ['bubble' => app(AskPortal::class)->showsBubble()] : false,
'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,
'flash' => [
'status' => fn () => $request->session()->get('status'),
'comment' => fn () => $request->session()->get('comment'),
'form_submitted' => fn () => $request->session()->get('form_submitted'),
],
];
}
private function footer(Request $request, User $user): mixed
{
$footer = app(Footer::class);
// Vorschau des Entwurfs aus dem Editor
if ($request->query('fusszeile') === 'entwurf' && $user->can('appearance.manage')) {
return $footer->render($user, draft: true);
}
if (! $footer->isActive()) {
return null;
}
// Schlüssel je Person und Fassung: nach „Veröffentlichen“ oder „Als Person anmelden“ neu laden
return Inertia::once(fn () => $footer->render($user))
->as('footer-'.substr(md5($footer->version().'|'.$user->id), 0, 12))
->until(600);
}
}