Loheide-eu-mitarbeiterplatt.../app/Http/Controllers/Api/HomeController.php
Friederich Loheide 7b20d40994
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 10m32s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 10m37s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 17m19s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 17m21s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 16m33s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 16m27s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 13m30s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 14m15s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 49s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m18s
App zeigt Plugins ohne neue App-Version (0.60.0)
API: Feed, Aufgaben, Schnellzugriffe, Menü; Einmal-Link für eingebettete
Portalseiten ohne Kopf- und Fußzeile.

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

74 lines
2.7 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\Controllers\Api;
use App\Feed\Feed;
use App\Http\Controllers\Controller;
use App\Support\Navigation;
use App\Support\QuickLinks;
use App\Tasks\Tasks;
use Carbon\CarbonImmutable;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Throwable;
/**
* Allgemeine Schnittstellen für die App: Was Plugins im Portal beisteuern (Feed, Aufgaben,
* Schnellzugriffe, Menü), erscheint so ohne neue App-Version. Seiten ohne eigenen
* App-Bildschirm öffnet die App eingebettet (webSession).
*/
class HomeController extends Controller
{
public function feed(Request $request, Feed $feed): JsonResponse
{
try {
$before = $request->filled('vor') ? CarbonImmutable::parse((string) $request->query('vor')) : null;
} catch (Throwable) {
$before = null;
}
return response()->json($feed->page($request->user(), $before));
}
public function tasks(Request $request, Tasks $tasks): JsonResponse
{
return response()->json(['data' => $tasks->forUser($request->user())]);
}
public function apps(Request $request, QuickLinks $links): JsonResponse
{
return response()->json(['data' => $links->forUser($request->user())]);
}
/** Hauptmenü wie im Portal (je Person gefiltert) – Plugins inklusive */
public function menu(Request $request, Navigation $navigation): JsonResponse
{
$map = fn (array $item) => [
'key' => (string) ($item['key'] ?? ''),
'label' => (string) ($item['label'] ?? ''),
'href' => $item['href'] ?? null,
'icon' => $item['icon'] ?? null,
'external' => (bool) ($item['new_tab'] ?? false) || (isset($item['href']) && preg_match('#^https?://#i', (string) $item['href'])),
];
return response()->json(['data' => array_values(array_map(fn (array $item) => [
...$map($item),
'children' => array_values(array_map($map, $item['children'] ?? [])),
], $navigation->items($request, $request->user())))]);
}
/**
* Einmal-Link, mit dem die App eine Portalseite eingebettet öffnet: angemeldet wie in
* der App, ohne Kopf- und Fußzeile des Portals. Gilt zwei Minuten und nur einmal.
*/
public function webSession(Request $request): JsonResponse
{
$data = $request->validate(['path' => ['required', 'string', 'max:500', 'regex:#^/(?!/)#']]);
$token = Str::random(48);
Cache::put('app-web-session:'.$token, ['user' => $request->user()->id, 'path' => $data['path']], now()->addMinutes(2));
return response()->json(['data' => ['url' => url('/app-sitzung/'.$token)]]);
}
}