App zeigt Plugins ohne neue App-Version (0.60.0)
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
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
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>
This commit is contained in:
parent
8cef93965e
commit
7b20d40994
145 changed files with 572 additions and 372 deletions
74
app/Http/Controllers/Api/HomeController.php
Normal file
74
app/Http/Controllers/Api/HomeController.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?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)]]);
|
||||
}
|
||||
}
|
||||
32
app/Http/Controllers/AppWebSessionController.php
Normal file
32
app/Http/Controllers/AppWebSessionController.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class AppWebSessionController extends Controller
|
||||
{
|
||||
/** Einmal-Link aus der App: anmelden, eingebettete Ansicht merken, zur Seite weiter */
|
||||
public function __invoke(Request $request, string $token): RedirectResponse
|
||||
{
|
||||
$data = Cache::pull('app-web-session:'.$token);
|
||||
$user = is_array($data) ? User::query()->find($data['user'] ?? 0) : null;
|
||||
|
||||
abort_unless($user && $user->is_active, 403, 'Der Link ist abgelaufen. Bitte in der App erneut öffnen.');
|
||||
|
||||
$web = Auth::guard('web');
|
||||
|
||||
if (! $web->check() || $web->id() !== $user->id) {
|
||||
$web->login($user);
|
||||
$request->session()->regenerate();
|
||||
}
|
||||
|
||||
$request->session()->put('embedded', true);
|
||||
|
||||
return redirect($data['path'] ?? '/');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue