Loheide-eu-mitarbeiterplatt.../app/Filament/Pages/Updates.php
Friederich Loheide 9ddc35a62c
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m30s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m28s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m31s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m36s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 1m45s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 1m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 1m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 1m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 54s
Rollen, Rechte und Zielgruppen
- Rollen mit globalen Rechten und Rechten für einzelne Objekte (z. B. „Beiträge
  schreiben in Kategorie MAV-Info“); Rollen sind additiv, Zuweisungen merken
  sich ihre Herkunft (manuell oder später Identity-Provider-Gruppe)
- Systemrolle „Administration“ ersetzt users.is_admin (Migration übernimmt
  bestehende Administratoren); nicht löschbar, man kann sie sich nicht selbst entziehen
- Rechte je Person vorberechnet und gecacht, Versionszähler invalidiert bei Änderungen
- Gate-Anbindung: registrierte Rechte entscheidet das Rechtesystem, Objektregeln
  die Policies; Admin-Seiten und Plugin-Ressourcen hinter passenden Rechten
- Redaktion nach Kategorie: Schreiben und Veröffentlichen getrennt, Liste im
  Admin auf eigene Kategorien beschränkt, ohne Veröffentlichungsrecht bleibt
  ein Beitrag Entwurf
- Zielgruppen (Rolle/Abteilung/Standort) für Kategorien und Termine als
  indizierte SQL-Bedingung in Listen, Detailseiten, Kacheln und .ics-Export
- Admin: Rollen-Verwaltung, „Rechte prüfen“, Redaktion und Sichtbarkeit direkt
  an Kategorie bzw. Termin
- Kern-Ressourcen explizit registriert, damit nach Updates liegengebliebene
  alte Dateien nicht doppelt geladen werden
- docs/PLUGINS.md für Plugin-Entwicklung; Demo-Rolle „MAV“

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

136 lines
4.6 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Support\Audit;
use App\Support\License\LicenseService;
use App\Support\License\LicenseStore;
use App\Support\License\ServerError;
use App\Support\License\ServerMessages;
use App\Support\Update\Changelog;
use App\Support\Update\Channels;
use App\Support\Update\InstalledVersion;
use App\Support\Update\Migrations;
use App\Support\Update\UpdateProgress;
use BackedEnum;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
use Throwable;
use UnitEnum;
/**
* Seite „Aktualisierung“: Version, Kanal, Update-Suche und -Installation,
* Migrationen, Änderungsprotokoll und Lizenz (docs/specs/self-updater.md).
*/
class Updates extends Page
{
protected string $view = 'filament.pages.updates';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedArrowPathRoundedSquare;
protected static string|UnitEnum|null $navigationGroup = 'System';
protected static ?int $navigationSort = 10;
protected static ?string $navigationLabel = 'Aktualisierung';
protected static ?string $title = 'Aktualisierung';
public static function canAccess(): bool
{
return auth()->user()?->can('updates.manage') ?? false;
}
protected static ?string $slug = 'aktualisierung';
public string $licenseEmail = '';
public string $licenseKey = '';
public ?string $licenseError = null;
public function mount(LicenseStore $license): void
{
$this->licenseEmail = (string) $license->email();
}
public function saveLicense(LicenseStore $license, LicenseService $service): void
{
$this->validate([
'licenseEmail' => ['required', 'email', 'max:255'],
'licenseKey' => [$license->hasLicense() ? 'nullable' : 'required', 'string', 'max:500'],
], attributes: ['licenseEmail' => 'Lizenz-E-Mail', 'licenseKey' => 'Lizenzschlüssel']);
$license->setLicense($this->licenseEmail, filled($this->licenseKey) ? $this->licenseKey : (string) $license->key());
$this->licenseKey = '';
Audit::log('license.saved', ['email' => $this->licenseEmail]);
$this->checkLicense($service);
}
public function checkLicense(LicenseService $service): void
{
$this->licenseError = null;
try {
$service->check();
Notification::make()->success()->title('Lizenz geprüft')->send();
} catch (ServerError $e) {
$this->licenseError = ServerMessages::for($e);
} catch (Throwable $e) {
$this->licenseError = 'Die Lizenz konnte nicht geprüft werden: '.$e->getMessage();
}
}
public function releaseDevice(LicenseService $service, LicenseStore $license): void
{
try {
$service->releaseDevice();
Audit::log('license.device_released', ['device_label' => $license->deviceLabel()]);
Notification::make()
->success()
->title('Installation abgemeldet')
->body('Der Geräteplatz ist wieder frei. Updates sind erst nach erneuter Lizenzprüfung wieder möglich.')
->send();
} catch (ServerError $e) {
Notification::make()->danger()->title('Abmelden fehlgeschlagen')->body(ServerMessages::for($e))->send();
}
}
/**
* @return array<string, mixed>
*/
protected function getViewData(): array
{
$version = app(InstalledVersion::class);
$license = app(LicenseStore::class);
$channels = app(Channels::class);
try {
$migrations = app(Migrations::class)->status();
} catch (Throwable) {
$migrations = [];
}
return [
'release' => $version->release(),
'shortSha' => $version->short(),
'channels' => $channels->all(),
'activeChannel' => $channels->active(),
'progress' => app(UpdateProgress::class)->get(),
'migrations' => $migrations,
'pendingMigrations' => count(array_filter($migrations, fn (array $m) => ! $m['ran'])),
'changelog' => app(Changelog::class)->sections(),
'hasLicense' => $license->hasLicense(),
'maskedKey' => ($key = $license->key()) ? str_repeat('•', 8).substr($key, -4) : null,
'licenseSummary' => app(LicenseService::class)->summary(),
'licenseStatusError' => ($code = $license->lastStatus()['error_code'] ?? null)
? ServerMessages::for(new ServerError($code, 0, $code))
: null,
'deviceLabel' => $license->deviceLabel(),
];
}
}