Ein neu angelegter Mandant war eine Sackgasse. Er bekam keine Website, also keinen Host, also keine Adresse – und der Host wird im Mandanten-Admin eingetragen, den er ohne Adresse nicht erreicht. „Im Admin öffnen" half nicht: ohne Domain landete es beim Mandanten des aktuellen Hosts. Einsprungsadressen gehören jetzt dem Betreiber, weil Webspace und Hosting ihm gehören und ein Mandant nicht die Adresse eines anderen auf sich zeigen lassen darf. Im Mandanten-Formular: Websites mit ihren Adressen. Beim Anlegen entstehen Website, Host-Einträge und eine leere Startseite – ohne Startseite antwortet die Website mit 404. Im Mandanten-Admin sind die Adressen nur noch sichtbar, nicht änderbar. Die Domain beim Hoster auf das Verzeichnis zu legen bleibt ein Schritt von Hand. Gesperrter Mandant: statt 404 ein Hinweis mit Status 503, Text je Mandant einstellbar. 503 hält die Seiten im Suchindex, weil die Sperre vorübergehend ist. Behoben: `URL::forceRootUrl(APP_URL)` zwang **alle** Links auf einen festen Host. Mit einem Mandanten unsichtbar; mit zwei Domains hätte jeder interne Link der zweiten Website auf die erste gezeigt. Der Ursprung ist jetzt der Host der aufgelösten Website. Neu: systemweite Einstellungen sind im Betreiber-Bereich änderbar (Löschfristen, Bot-Schutz, Flutgrenze, Sicherungen, Portal-Fristen, Versandweg, SMTP, harte Mail-Umleitung, Tokens). Leer heißt: der Wert der .env gilt wieder – und zwar sofort, nicht erst beim nächsten Start. Geheimnisse liegen verschlüsselt. Datenbank-Zugang und APP_KEY bleiben in der .env, weil sie gebraucht werden, um die Datenbank zu öffnen und das Gespeicherte zu entschlüsseln. 253 Feature-Tests grün. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
115 lines
4.0 KiB
PHP
115 lines
4.0 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Operator\Pages;
|
||
|
||
use App\Support\SystemSettings;
|
||
use BackedEnum;
|
||
use Filament\Actions\Action;
|
||
use Filament\Forms\Components\Select;
|
||
use Filament\Forms\Components\TextInput;
|
||
use Filament\Notifications\Notification;
|
||
use Filament\Pages\Page;
|
||
use Filament\Schemas\Components\Actions;
|
||
use Filament\Schemas\Components\EmbeddedSchema;
|
||
use Filament\Schemas\Components\Form;
|
||
use Filament\Schemas\Components\Section;
|
||
use Filament\Schemas\Components\Text;
|
||
use Filament\Schemas\Schema;
|
||
use Filament\Support\Icons\Heroicon;
|
||
|
||
/**
|
||
* The settings of the whole installation. They are the baseline every landlord is bound by, and a
|
||
* landlord's admin never reaches this page.
|
||
*
|
||
* Empty means: the value from the server's .env applies again. Database credentials and APP_KEY are not
|
||
* here and cannot be – they are needed to open the database and to decrypt what is stored in it.
|
||
*/
|
||
class SystemSettingsPage extends Page
|
||
{
|
||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedAdjustmentsHorizontal;
|
||
|
||
protected static ?string $navigationLabel = 'Einstellungen';
|
||
|
||
protected static ?string $title = 'Systemweite Einstellungen';
|
||
|
||
protected static ?string $slug = 'einstellungen';
|
||
|
||
protected static ?int $navigationSort = 3;
|
||
|
||
/** @var array<string, mixed> */
|
||
public array $data = [];
|
||
|
||
public function mount(): void
|
||
{
|
||
$this->form->fill(collect(SystemSettings::EDITABLE)
|
||
->mapWithKeys(fn (array $definition, string $key): array => [self::field($key) => SystemSettings::get($key)])
|
||
->all());
|
||
}
|
||
|
||
public function form(Schema $schema): Schema
|
||
{
|
||
$sections = collect(SystemSettings::EDITABLE)
|
||
->groupBy(fn (array $definition): string => $definition[2], preserveKeys: true)
|
||
->map(fn ($group, string $section) => Section::make($section)
|
||
->columns(2)
|
||
->schema($group->keys()->map(fn (string $key) => $this->field_($key))->all()));
|
||
|
||
return $schema
|
||
->statePath('data')
|
||
->components([
|
||
Text::make('Leer lassen heißt: der Wert aus der .env des Servers gilt wieder. Datenbank-Zugang und APP_KEY stehen bewusst nicht hier – sie werden gebraucht, um die Datenbank überhaupt zu öffnen und das Gespeicherte zu entschlüsseln.'),
|
||
...$sections->values()->all(),
|
||
]);
|
||
}
|
||
|
||
public function content(Schema $schema): Schema
|
||
{
|
||
return $schema->components([
|
||
Form::make([EmbeddedSchema::make('form')])
|
||
->id('form')
|
||
->livewireSubmitHandler('save')
|
||
->footer([Actions::make([Action::make('save')->label('Speichern')->submit('save')])]),
|
||
]);
|
||
}
|
||
|
||
public function save(): void
|
||
{
|
||
$data = $this->form->getState();
|
||
|
||
SystemSettings::save(collect(SystemSettings::EDITABLE)
|
||
->mapWithKeys(fn (array $definition, string $key): array => [$key => $data[self::field($key)] ?? null])
|
||
->all());
|
||
|
||
Notification::make()->title('Gespeichert')->success()->send();
|
||
}
|
||
|
||
/**
|
||
* Config keys contain dots, which Filament would read as nesting.
|
||
*/
|
||
private static function field(string $key): string
|
||
{
|
||
return str_replace('.', '__', $key);
|
||
}
|
||
|
||
private function field_(string $key): TextInput|Select
|
||
{
|
||
[$label, $kind, , $help] = SystemSettings::EDITABLE[$key];
|
||
$name = self::field($key);
|
||
|
||
if ($kind === 'mailer') {
|
||
return Select::make($name)
|
||
->label($label)
|
||
->helperText($help)
|
||
->options(['smtp' => 'SMTP (echter Versand)', 'log' => 'Nur Logdatei (kein Versand)', 'array' => 'Verwerfen (nur für Tests)']);
|
||
}
|
||
|
||
$field = TextInput::make($name)->label($label)->helperText($help);
|
||
|
||
return match ($kind) {
|
||
'int' => $field->numeric()->integer()->minValue(0),
|
||
'secret' => $field->password()->revealable()->autocomplete(false),
|
||
default => $field,
|
||
};
|
||
}
|
||
}
|