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>
115 lines
3.1 KiB
PHP
115 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Support\Settings;
|
|
use App\Tenancy\TenantDefaults;
|
|
use Database\Factories\TenantFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
/**
|
|
* A landlord. Owns websites, apartments, guests, bookings and settings. One account can belong
|
|
* to several landlords; the operator is not a landlord.
|
|
*/
|
|
#[Fillable([
|
|
'name', 'slug', 'is_active',
|
|
'owner_name', 'owner_street', 'owner_city', 'owner_phone', 'contact_email', 'notification_emails',
|
|
'sender_name', 'sender_email',
|
|
'bank_account_holder', 'bank_iban', 'bank_bic', 'bank_name', 'tax_note',
|
|
'operating_mode', 'test_recipient',
|
|
'deposit_due_days', 'review_request_after_days', 'guest_retention_years', 'retention_inquiry_months',
|
|
'retention_portal_email_excerpt_days', 'retention_attribution_months',
|
|
'spam_min_seconds', 'spam_per_ip_per_hour', 'spam_per_email_per_day', 'spam_open_requests_per_email', 'spam_max_links',
|
|
'channel_stale_after_minutes', 'channel_task_reminder_after_minutes',
|
|
])]
|
|
class Tenant extends Model
|
|
{
|
|
/** @use HasFactory<TenantFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The landlord the existing single-website data belongs to.
|
|
*/
|
|
public static function stommer(): self
|
|
{
|
|
return static::query()->firstOrCreate(
|
|
['slug' => 'stommer'],
|
|
['name' => 'Stommer'] + TenantDefaults::forLegacyLandlord(encryptBank: false),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_active' => 'boolean',
|
|
'bank_account_holder' => 'encrypted',
|
|
'bank_iban' => 'encrypted',
|
|
'bank_bic' => 'encrypted',
|
|
'bank_name' => 'encrypted',
|
|
'tax_note' => 'encrypted',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<Site, $this>
|
|
*/
|
|
public function sites(): HasMany
|
|
{
|
|
return $this->hasMany(Site::class);
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<Property, $this>
|
|
*/
|
|
public function properties(): HasMany
|
|
{
|
|
return $this->hasMany(Property::class);
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<TenantService, $this>
|
|
*/
|
|
public function services(): HasMany
|
|
{
|
|
return $this->hasMany(TenantService::class);
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<ServiceUsage, $this>
|
|
*/
|
|
public function serviceUsages(): HasMany
|
|
{
|
|
return $this->hasMany(ServiceUsage::class);
|
|
}
|
|
|
|
public function isLive(): bool
|
|
{
|
|
return $this->operating_mode === 'live';
|
|
}
|
|
|
|
/**
|
|
* Notification addresses of this landlord.
|
|
*
|
|
* @return list<string>
|
|
*/
|
|
public function notificationRecipients(): array
|
|
{
|
|
return Settings::addressList($this->notification_emails);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsToMany<User, $this>
|
|
*/
|
|
public function users(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(User::class)->withPivot('role')->withTimestamps();
|
|
}
|
|
}
|