Mandanten Phase 3: Einstellungen, Texte und Dienste gehören dem Mandanten
Vermieterdaten, Bank, Steuerangabe, Adressen, Betriebsart und Fristen sind
Spalten von `tenants`. `App\Tenancy\TenantConfig` legt sie über
`config('fewo.*')` und `mail.from`, sobald der Mandantenkontext wechselt –
so lesen Vorlagen, Mails und der Mietvertrag weiter dieselben Schlüssel und
`resources/themes/**` bleibt unangetastet.
Die `.env` ist die Grundlinie: Rückfall, solange kein Mandant feststeht, und
Grenze für Löschfristen und Bot-Schutz (nur verschärfen, nicht lockern). Die
Flutgrenze bleibt global. Bank, Steuerangabe und eigene Dienst-Schlüssel
liegen verschlüsselt.
Die Seite System › Betrieb schreibt jetzt den Mandanten und enthält
zusätzlich Vermieterdaten, Bank und die Fristen. Tabelle `settings` und
Modell `Setting` entfallen; die Migration übernimmt die bisherigen Werte
aus `settings` und der Konfiguration in den Mandanten Stommer.
Neu: `tenant_services` (Freischaltung je Dienst mit optionalem eigenem
API-Schlüssel, nur im Betreiber-Bereich schaltbar) und `service_usages`.
Es zählt noch nichts, weil kein Dienst aufruft.
235 Feature-Tests grün. Der Umbauweg wurde zusätzlich auf einer Kopie der
lokalen Datenbank durchgespielt.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
12e4079126
commit
e6d4d89141
24 files changed
+1123
-135
No files matched your search
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Operator\Concerns;
|
||||
|
||||
use App\Enums\TenantServiceKey;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\TenantService;
|
||||
|
||||
/**
|
||||
* The service switches of the tenant form. They live in their own table, so the form state is read and
|
||||
* written separately from the landlord's own columns.
|
||||
*/
|
||||
trait EditsTenantServices
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$tenant = $this->record;
|
||||
|
||||
if (! $tenant instanceof Tenant) {
|
||||
return $data; // creating: there is nothing to read yet
|
||||
}
|
||||
|
||||
$data['services'] = $tenant->services
|
||||
->mapWithKeys(fn (TenantService $service): array => [$service->service => [
|
||||
'is_enabled' => $service->is_enabled,
|
||||
'api_key' => $service->api_key,
|
||||
]])
|
||||
->all();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
return $this->withoutServices($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
return $this->withoutServices($data);
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
$this->saveServices();
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
$this->saveServices();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function withoutServices(array $data): array
|
||||
{
|
||||
$this->services = is_array($data['services'] ?? null) ? $data['services'] : [];
|
||||
|
||||
unset($data['services']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function saveServices(): void
|
||||
{
|
||||
$tenant = $this->record;
|
||||
|
||||
if (! $tenant instanceof Tenant) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (TenantServiceKey::cases() as $service) {
|
||||
$state = $this->services[$service->value] ?? [];
|
||||
|
||||
$tenant->services()->updateOrCreate(
|
||||
['service' => $service->value],
|
||||
[
|
||||
'is_enabled' => (bool) ($state['is_enabled'] ?? false),
|
||||
'api_key' => filled($state['api_key'] ?? null) ? $state['api_key'] : null,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
$tenant->unsetRelation('services');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Operator;
|
||||
|
||||
use App\Enums\TenantServiceKey;
|
||||
use App\Filament\Operator\Tenants\Pages\CreateTenant;
|
||||
use App\Filament\Operator\Tenants\Pages\EditTenant;
|
||||
use App\Filament\Operator\Tenants\Pages\ListTenants;
|
||||
@@ -13,6 +14,8 @@
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Fieldset;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
@@ -51,6 +54,19 @@ public static function form(Schema $schema): Schema
|
||||
->label('Aktiv')
|
||||
->helperText('Ein gesperrter Mandant ist von außen nicht mehr erreichbar. Der Betreiber kommt weiter hinein.')
|
||||
->default(true),
|
||||
Section::make('Dienste')
|
||||
->description('Welche Dienste dieser Mandant nutzen darf. Ein eigener Schlüssel ist freiwillig; bleibt er leer, gilt später der Schlüssel des Betreibers.')
|
||||
->columnSpanFull()
|
||||
->schema(array_map(fn (TenantServiceKey $service): Fieldset => Fieldset::make($service->label())
|
||||
->columns(2)
|
||||
->schema([
|
||||
Toggle::make('services.'.$service->value.'.is_enabled')->label('Freigeschaltet'),
|
||||
TextInput::make('services.'.$service->value.'.api_key')
|
||||
->label('Eigener API-Schlüssel')
|
||||
->password()
|
||||
->revealable()
|
||||
->maxLength(255),
|
||||
]), TenantServiceKey::cases())),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -60,6 +76,7 @@ public static function table(Table $table): Table
|
||||
->columns([
|
||||
TextColumn::make('name')->label('Name')->searchable(),
|
||||
TextColumn::make('slug')->label('Kurzname'),
|
||||
TextColumn::make('services_count')->label('Dienste')->counts(['services' => fn ($query) => $query->where('is_enabled', true)]),
|
||||
ToggleColumn::make('is_active')->label('Aktiv'),
|
||||
])
|
||||
->recordActions([
|
||||
|
||||
@@ -2,10 +2,16 @@
|
||||
|
||||
namespace App\Filament\Operator\Tenants\Pages;
|
||||
|
||||
use App\Filament\Operator\Concerns\EditsTenantServices;
|
||||
use App\Filament\Operator\TenantResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateTenant extends CreateRecord
|
||||
{
|
||||
use EditsTenantServices;
|
||||
|
||||
protected static string $resource = TenantResource::class;
|
||||
|
||||
/** @var array<string, array<string, mixed>> */
|
||||
public array $services = [];
|
||||
}
|
||||
@@ -2,10 +2,16 @@
|
||||
|
||||
namespace App\Filament\Operator\Tenants\Pages;
|
||||
|
||||
use App\Filament\Operator\Concerns\EditsTenantServices;
|
||||
use App\Filament\Operator\TenantResource;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditTenant extends EditRecord
|
||||
{
|
||||
use EditsTenantServices;
|
||||
|
||||
protected static string $resource = TenantResource::class;
|
||||
|
||||
/** @var array<string, array<string, mixed>> */
|
||||
public array $services = [];
|
||||
}
|
||||
Reference in new issue
Block a user