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>
109 lines
4.2 KiB
PHP
109 lines
4.2 KiB
PHP
<?php
|
|
|
|
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;
|
|
use App\Models\Tenant;
|
|
use App\Models\TenantAccessLog;
|
|
use BackedEnum;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\EditAction;
|
|
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;
|
|
use Filament\Tables\Columns\ToggleColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
class TenantResource extends Resource
|
|
{
|
|
protected static ?string $model = Tenant::class;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBuildingOffice;
|
|
|
|
protected static ?string $modelLabel = 'Mandant';
|
|
|
|
protected static ?string $pluralModelLabel = 'Mandanten';
|
|
|
|
protected static ?string $navigationLabel = 'Mandanten';
|
|
|
|
protected static ?int $navigationSort = 1;
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
TextInput::make('name')
|
|
->label('Name')
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('slug')
|
|
->label('Kurzname')
|
|
->required()
|
|
->alphaDash()
|
|
->unique(ignoreRecord: true)
|
|
->maxLength(255),
|
|
Toggle::make('is_active')
|
|
->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())),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $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([
|
|
EditAction::make(),
|
|
Action::make('openAdmin')
|
|
->label('Im Admin öffnen')
|
|
->icon(Heroicon::OutlinedArrowTopRightOnSquare)
|
|
->action(function (Tenant $record) {
|
|
TenantAccessLog::query()->create([
|
|
'tenant_id' => $record->id,
|
|
'user_id' => auth()->id(),
|
|
]);
|
|
|
|
$domain = $record->sites()->withoutGlobalScope('tenant')->whereNotNull('domain')->value('domain');
|
|
|
|
return redirect(is_string($domain) && $domain !== '' ? 'https://'.$domain.'/admin' : url('/admin'));
|
|
}),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListTenants::route('/'),
|
|
'create' => CreateTenant::route('/create'),
|
|
'edit' => EditTenant::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|