clusev/app/Livewire/System/Index.php

90 lines
3.3 KiB
PHP

<?php
namespace App\Livewire\System;
use App\Models\Setting;
use App\Services\DeploymentService;
use Livewire\Attributes\Layout;
use Livewire\Attributes\On;
use Livewire\Attributes\Title;
use Livewire\Component;
/**
* System settings — dashboard-configurable Domain + TLS and the release channel.
*
* Domain & TLS: READ-ONLY status. The panel domain is an install-time decision
* (APP_DOMAIN) so it stays consistent with URL/WebSocket/cookie security; Caddy then
* issues, renews and HTTP→HTTPS-redirects fully automatically. Nothing to apply or
* reload here — to change the domain, re-run install.sh.
*
* Release-Kanal: a stable|beta choice persisted as a Setting (default from
* config('clusev.channel')), audited on change.
*/
#[Layout('layouts.app')]
#[Title('System — Clusev')]
class Index extends Component
{
/** Valid user-facing release channels with their German descriptions. */
public const CHANNELS = [
'stable' => 'Nur getestete, vom Maintainer freigegebene Releases (getaggte Versionen). Empfohlen für den Produktivbetrieb.',
'beta' => 'Vorabversionen kommender Releases zum Testen neuer Funktionen. Kann instabil sein. Entwicklungs-Builds werden Nutzern nie angeboten.',
];
/** Install-time panel domain (read-only display). */
public string $domain = '';
public string $channel = 'stable';
public function mount(DeploymentService $deployment): void
{
$this->domain = (string) ($deployment->domain() ?? '');
$channel = Setting::get('release_channel', config('clusev.channel')) ?? 'stable';
// Clamp to a valid user channel — a stale/legacy value (e.g. 'dev') falls back to stable.
$this->channel = array_key_exists($channel, self::CHANNELS) ? $channel : 'stable';
}
/** Release channel changes are audited (confirmation via the shared modal). */
public function confirmChannel(string $channel): void
{
if (! array_key_exists($channel, self::CHANNELS) || $channel === $this->channel) {
return;
}
$this->dispatch('openModal',
component: 'modals.confirm-action',
arguments: [
'heading' => 'Release-Kanal wechseln',
'body' => 'Der Release-Kanal wird auf "'.$channel.'" gesetzt. Updates werden dann aus dieser Quelle bezogen.',
'confirmLabel' => 'Wechseln',
'danger' => false,
'icon' => 'git-branch',
'auditAction' => 'system.settings_updated',
'auditTarget' => 'release_channel='.$channel,
'event' => 'channelChanged',
'params' => ['channel' => $channel],
'notify' => 'Release-Kanal auf "'.$channel.'" gesetzt.',
],
);
}
#[On('channelChanged')]
public function applyChannel(string $channel): void
{
if (! array_key_exists($channel, self::CHANNELS)) {
return;
}
Setting::put('release_channel', $channel);
$this->channel = $channel;
}
public function render(DeploymentService $deployment)
{
return view('livewire.system.index', [
'hasTls' => $this->domain !== '',
'panelUrl' => $deployment->panelUrl(),
'channels' => self::CHANNELS,
]);
}
}