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>
91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
<?php
|
||
|
||
namespace App\Support;
|
||
|
||
use App\Models\Tenant;
|
||
use App\Tenancy\TenantConfig;
|
||
|
||
/**
|
||
* Operating mode and addresses of the current landlord (admin page System › Betrieb, stored on the landlord).
|
||
* In **test mode** (the default until the site is switched live) every e-mail goes to the test recipient only,
|
||
* whatever address was entered on the website. Without any landlord the .env values apply.
|
||
*/
|
||
class Settings
|
||
{
|
||
public const MODE_TEST = 'test';
|
||
|
||
public const MODE_LIVE = 'live';
|
||
|
||
/**
|
||
* The landlord of the context, else the only landlord.
|
||
*/
|
||
public static function tenant(): ?Tenant
|
||
{
|
||
return app(TenantConfig::class)->effectiveTenant();
|
||
}
|
||
|
||
/**
|
||
* The recipients of internal notifications (the landlord's setting, else FEWO_NOTIFICATION_EMAIL while no landlord is known).
|
||
*
|
||
* @return list<string>
|
||
*/
|
||
public static function notificationRecipients(): array
|
||
{
|
||
return self::tenant()?->notificationRecipients()
|
||
?: self::addressList((string) config('fewo.notification_email'));
|
||
}
|
||
|
||
/**
|
||
* "a@x.de, b@y.de; c@z.de" → valid addresses only.
|
||
*
|
||
* @return list<string>
|
||
*/
|
||
public static function addressList(?string $value): array
|
||
{
|
||
return array_values(array_filter(
|
||
array_map('trim', preg_split('/[,;\s]+/', (string) $value) ?: []),
|
||
fn (string $address): bool => filter_var($address, FILTER_VALIDATE_EMAIL) !== false,
|
||
));
|
||
}
|
||
|
||
public static function isLive(): bool
|
||
{
|
||
return (self::tenant()?->operating_mode ?? self::MODE_TEST) === self::MODE_LIVE;
|
||
}
|
||
|
||
/**
|
||
* Where all e-mails go instead of their real recipients, or null when mails are delivered normally.
|
||
* FEWO_MAIL_REDIRECT_TO in .env always wins (hard override for test servers).
|
||
*/
|
||
public static function mailRedirect(): ?string
|
||
{
|
||
return self::mailRedirectFor(self::tenant());
|
||
}
|
||
|
||
public static function mailRedirectFor(?Tenant $tenant): ?string
|
||
{
|
||
$override = config('fewo.mail_redirect_to');
|
||
if (filled($override)) {
|
||
return (string) $override;
|
||
}
|
||
|
||
if ($tenant?->isLive()) {
|
||
return null;
|
||
}
|
||
|
||
// A landlord without any address of their own must not fall through to normal delivery: the operator's
|
||
// address catches the mails until the landlord has entered their own.
|
||
$recipients = $tenant?->notificationRecipients() ?: self::addressList((string) config('fewo.notification_email'));
|
||
|
||
return $tenant?->test_recipient ?: ($recipients[0] ?? null);
|
||
}
|
||
|
||
/**
|
||
* Applies the redirect of the current landlord to the mailer; called after saving.
|
||
*/
|
||
public static function applyMailRouting(): void
|
||
{
|
||
app(TenantConfig::class)->refresh();
|
||
}
|
||
}
|