Mandantenabschluss: Marken, Vertragsdateien und Archive trennen
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m23s

This commit is contained in:
Lars committed 2026-10-26 17:07:11 +01:00
1 parent 86374b1659
commit 06df80e4db
45 files changed
+592 -99

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
<?php
namespace App\Console\Commands;
use App\Models\Site;
use App\Tenancy\TenantContext;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
#[Signature('sites:import-stommer-brand {site : ID der bestehenden Stommer-Website}')]
#[Description('Copy the legacy Stommer brand into its own website without replacing uploaded graphics')]
class ImportSiteBrand extends Command
{
/**
* Execute the console command.
*/
public function handle(): int
{
$site = Site::withoutGlobalScope('tenant')->with('tenant')->find($this->argument('site'));
if ($site === null || $site->tenant?->slug !== 'stommer') {
$this->error('Nur die bestehende Stommer-Website darf diese Marke übernehmen.');
return self::FAILURE;
}
$seebad = $site->theme === 'seebad';
$sources = [
Site::BRAND_LOGO => $seebad ? resource_path('themes/seebad/img/logo-bildmarke-720.webp') : public_path('brand/logo.svg'),
Site::BRAND_FAVICON => $seebad ? resource_path('themes/seebad/img/favicon.svg') : public_path('brand/favicon.svg'),
Site::BRAND_DOCUMENT_LOGO => public_path('brand/logo-600.png'),
];
foreach ($sources as $collection => $path) {
if (! $site->hasMedia($collection) && ! is_file($path)) {
$this->error('Markenquelle fehlt: '.$path);
return self::FAILURE;
}
}
app(TenantContext::class)->run($site->tenant, function () use ($site, $sources): void {
foreach ($sources as $collection => $path) {
if ($site->hasMedia($collection)) {
$this->line($collection.': vorhandene Grafik beibehalten.');
continue;
}
$site->addMedia($path)->preservingOriginal()->toMediaCollection($collection);
$this->info($collection.': übernommen.');
}
});
return self::SUCCESS;
}
}
+2 -1
View File
@@ -19,9 +19,10 @@ class RentalContract
public function generate(Booking $booking, bool $draft = false): string
{
$booking->loadMissing(['guest', 'property']);
$path = $draft
$filename = $draft
? "contracts/Angebot-{$booking->reference}-v{$booking->offer_version}.pdf"
: "contracts/Mietvertrag-{$booking->reference}.pdf";
$path = "contracts/tenants/{$booking->tenant_id}/bookings/{$booking->id}/".basename($filename);
// The logo is embedded as a file: the PDF is rendered on the server and must not depend on
// fetching anything over the network. Each website has its own (A14).
@@ -68,12 +68,12 @@ public static function configure(Schema $schema): Schema
SpatieMediaLibraryFileUpload::make('logo')
->label('Logo')
->collection(Site::BRAND_LOGO)
->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp'])
->helperText('SVG bevorzugt – bleibt in jeder Größe scharf.'),
->acceptedFileTypes(['image/png', 'image/webp'])
->helperText('PNG oder WebP. SVG-Dateien werden nur aus geprüften Quellen übernommen.'),
SpatieMediaLibraryFileUpload::make('favicon')
->label('Favicon')
->collection(Site::BRAND_FAVICON)
->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/x-icon'])
->acceptedFileTypes(['image/png', 'image/x-icon'])
->helperText('Das kleine Zeichen im Browser-Tab.'),
SpatieMediaLibraryFileUpload::make('document_logo')
->label('Logo für E-Mail und Vertrag')
+55 -5
View File
@@ -2,13 +2,16 @@
namespace App\Tenancy;
use App\Models\Booking;
use App\Models\Photo;
use App\Models\Site;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Storage;
use RuntimeException;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use ZipArchive;
@@ -192,25 +195,39 @@ private function rowsOf(string $table, Tenant $tenant): array
}
/**
* Photos keep their files through Spatie's media library; they hang off the photo, not off the landlord,
* so they are collected through the photos of this landlord.
* Include media metadata, original files, conversions and every retained document version.
*/
private function addFiles(ZipArchive $zip, Tenant $tenant): void
{
foreach ($this->mediaOf($tenant) as $media) {
$mediaItems = $this->mediaOf($tenant);
$zip->addFromString('daten/media.json', (string) $mediaItems->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
foreach ($mediaItems as $media) {
$path = $media->getPath();
if (is_string($path) && File::exists($path)) {
$zip->addFile($path, 'dateien/'.$media->id.'-'.$media->file_name);
$directory = dirname($path);
foreach (File::allFiles($directory) as $file) {
$relative = str_replace('\\', '/', substr($file->getPathname(), strlen($directory) + 1));
$zip->addFile($file->getPathname(), 'dateien/'.$media->id.'-'.$relative);
}
}
}
foreach ($this->documentPaths($tenant) as $path) {
$zip->addFile(Storage::disk('local')->path($path), 'dateien/local/'.$path);
}
}
private function deleteFiles(Tenant $tenant): void
{
$documents = $this->documentPaths($tenant);
foreach ($this->mediaOf($tenant) as $media) {
$media->delete(); // removes the stored file as well
}
Storage::disk('local')->delete($documents);
}
/**
@@ -220,10 +237,43 @@ private function mediaOf(Tenant $tenant): Collection
{
return app(TenantContext::class)->run(
$tenant,
fn () => Photo::query()->with('media')->get()->flatMap(fn (Photo $photo) => $photo->media),
fn () => Photo::query()->with('media')->get()->flatMap(fn (Photo $photo) => $photo->media)
->concat(Site::query()->with('media')->get()->flatMap(fn (Site $site) => $site->media)),
);
}
/**
* New documents have a tenant directory, including earlier offer versions. Existing installations
* also have flat paths: accept only those explicitly referenced by this tenant and never a shared file.
*
* @return list<string>
*/
private function documentPaths(Tenant $tenant): array
{
$disk = Storage::disk('local');
$paths = $disk->allFiles('contracts/tenants/'.$tenant->id);
$bookings = Booking::withoutGlobalScope('tenant')->where('tenant_id', $tenant->id)->get(['contract_path', 'offer_path']);
foreach ($bookings as $booking) {
foreach ([$booking->contract_path, $booking->offer_path] as $path) {
if (! is_string($path) || ! preg_match('~\Acontracts/[^/\\\\]+\.pdf\z~', $path) || ! $disk->exists($path)) {
continue;
}
$shared = Booking::withoutGlobalScope('tenant')->where('tenant_id', '!=', $tenant->id)
->where(fn ($query) => $query->where('contract_path', $path)->orWhere('offer_path', $path))->exists();
if ($shared) {
throw new RuntimeException('Vertragsdatei ist mehreren Mandanten zugeordnet: '.$path);
}
$paths[] = $path;
}
}
return array_values(array_unique($paths));
}
private function hasTenantColumn(string $table): bool
{
static $known = [];
+1
View File
@@ -59,6 +59,7 @@ class TenantConfig
* @var array<string, string>
*/
private const OWNED = [
'app.name' => 'name',
'fewo.owner.name' => 'owner_name',
'fewo.owner.street' => 'owner_street',
'fewo.owner.city' => 'owner_city',
+1 -1
View File
@@ -1,6 +1,6 @@
# Betrieb: Umgebungen, Zugänge, Einrichtung
Stand: 22.10.2026. Dieses Dokument beschreibt den **tatsächlichen Stand** der Installationen, damit jede neue Arbeitssitzung (Mensch oder KI) ohne Vorwissen weitermachen kann. Allgemeine Abläufe des Deployments stehen in [DEPLOYMENT.md](DEPLOYMENT.md), das fachliche Konzept in [KONZEPT.md](KONZEPT.md).
Stand: 26.10.2026. Aktuell bestätigt: Test unter **www.stommer.info** und `stommer.info`, SSH-Serverpfad **`test.fewo-stommer.de/`**. `dev.fewo-stommer.de/` existiert nicht. Produktion ist noch nicht eingerichtet: ein vorhandener leerer Ordner ist keine fertige Umgebung; eigene MariaDB, `.env`, persistente Daten und Domainzuordnung fehlen. Produktion bleibt in `pipeline.toml` gesperrt. Entwicklung und Testdeploy laufen über `develop` und PipelineManager; die manuellen Skripte unten sind Wartungswerkzeuge. Weitere Abläufe: [DEPLOYMENT.md](DEPLOYMENT.md).
> **Geheimnisse stehen nie im Repository und nie im Chat.** Passwörter (Datenbank, E-Mail), `APP_KEY`, Tokens und private SSH-Schlüssel liegen nur in `shared/.env` auf dem Server bzw. im Vaultwarden von Lars. Hier ist nur dokumentiert, *wo* sie liegen.
+1 -1
View File
@@ -21,7 +21,7 @@ ## 1. Prinzip
Auf dem Server werden nur **bash, tar und PHP-CLI** gebraucht – kein Composer, kein Node, kein Git, kein rsync.
Die Werkzeugumgebung wird im eigenen Repository `C:\dev\pipelinemanager` entwickelt und als lokales Image `pipeline-manager:0.1.0` auf dem Pi freigegeben. Das Image bleibt nach dem Entfernen eines Job-Containers erhalten. Der Ablauf folgt Tsumugus Docker-Aufträgen auf dem vorhandenen Host-Runner (`ubuntu-latest`), führt Tests jedoch am exakten Commit vor dem Upload aus. Keine PHP-/Node-Installation auf dem Host und kein Build auf dem Entwicklungsrechner für automatische Deployments.
Die Werkzeugumgebung wird im eigenen Repository `C:\dev\pipelinemanager` entwickelt und als lokales Image `pipeline-manager:0.1.1` auf dem Pi freigegeben. Das Image bleibt nach dem Entfernen eines Job-Containers erhalten. Der Ablauf folgt Tsumugus Docker-Aufträgen auf dem vorhandenen Host-Runner (`ubuntu-latest`), führt Tests jedoch am exakten Commit vor dem Upload aus. Keine PHP-/Node-Installation auf dem Host und kein Build auf dem Entwicklungsrechner für automatische Deployments.
FeWo definiert nur seine prepare/test/finalize-Befehle, erforderlichen Dateien, Laravel-Hooks, persistenten Pfade und Ziele in `pipeline.toml`. Gemeinsame Paket-, Sicherungs-, Upload- und Rückfalllogik liegt im PipelineManager. Der bisherige manuelle Weg über `scripts/deploy.sh` bleibt als bestehender Wartungsweg erhalten, bis die neue Anbindung vollständig auf Test bestätigt ist.
+3 -3
View File
@@ -1,6 +1,6 @@
# Mandantenfähigkeit – Umbauplan
Stand: 26.10.2026 · **Phasen 1 bis 5, Anwendungsseite von Phase 6 und Kern von Phase 7 umgesetzt und ausgeliefert.** Offen: der Theme-Teil von Phase 6 (§6 der Zusammenarbeit); optionale neue Wohnungsübersichts-/Suchbausteine sind nicht Teil des abgeschlossenen Phase-7-Kerns · Anforderungen: [MANDANTEN-ANFORDERUNGEN.md](MANDANTEN-ANFORDERUNGEN.md) · Design: [DESIGN-KONZEPT.md](DESIGN-KONZEPT.md) §7 · Übergabe: [STATUS.md](STATUS.md) Abschnitt 7
Stand: 26.10.2026 · **Phasen 1–6 und Kern von Phase 7 umgesetzt.** Abschließender Testdeploy des Theme-/Dateiabschlusses ausstehend, siehe STATUS. Neue Wohnungsübersichts-/Suchbausteine und Subscription/Abrechnung gehören zur funktionalen Weiterentwicklung. Anforderungen: [MANDANTEN-ANFORDERUNGEN.md](MANDANTEN-ANFORDERUNGEN.md).
Kein Portal, kein Marktplatz. Das Produkt bleibt die eigene Website eines Vermieters mit Vermietung. Wenige Mandanten, eine gemeinsame Datenbank, Laravel und Filament bleiben die Basis. Ein Python-Dienst ist nicht Teil dieses Umbaus.
@@ -261,7 +261,7 @@ ### Phase 5 – Abnahme der Trennung und Kündigung · umgesetzt
Tests: Nach der Löschung von A ist B vollständig da, inklusive Dateien und Buchungsnummern. Export von A enthält keine Zeile von B.
### Phase 6 – Marke und Bildwelt · Anwendungsseite umgesetzt (24.10.), Theme-Teil offen
### Phase 6 – Marke und Bildwelt · vollständig umgesetzt (26.10.)
A14, A18, A19, A20, A22. Nicht zusammen mit Phase 1–5, und nicht solange der Branch `theme/<key>` die Vorlagen noch nicht nachziehen kann.
@@ -271,7 +271,7 @@ ### Phase 6 – Marke und Bildwelt · Anwendungsseite umgesetzt (24.10.), Theme-
**Umgesetzt am 24.10. (ohne eine Theme-Datei zu ändern):** Bildwelten als Pakete in `resources/image-worlds/<key>/`, Registry, Auswahl an der Website, Überschreibung an der Wohnung; `$theme->motif()`/`hasMotif()`/`imageWorld()` als Platz-API; `image-worlds:check`. Marke als Medien der Website mit `$theme->brand()`, eingebettet im Mietvertrag. Die Ostsee-Grafiken wurden **kopiert**, nicht verschoben.
**Offen und ein Vertragsfall (ZUSAMMENARBEIT.md §6):** `ostsee-licht` von `partials/brand` auf Plätze umstellen, das Favicon in beiden Themes zuerst bei `$theme->brand('favicon')` erfragen, und Seebads `motifs/`-Ordner gegen die Bildwelt tauschen. `public/brand/` entfällt erst danach.
**Abschluss 26.10.:** Beide Themes nutzen Website-Marke und Bildwelt-Plätze; ohne Marke wird keine fremde Identität angezeigt. Alte Grafikdateien bleiben nur als Importquellen erhalten. `sites:import-stommer-brand <site-id>` übernimmt die vorhandene Stommer-Marke ohne Überschreiben. Auch HTML-/Textmails sind mandanteneigen. Verträge und Angebote haben getrennte Speicherpfade; Export/Löschung schließen Website-Medien und Vertragsdateien ein. Regressionstests: `TenantBrandRenderingTest`, `TenantFilesTest`. Der Vorlagenvertrag ist in ZUSAMMENARBEIT §6 eingetragen.
### Phase 7 – Mehrere Wohnungen je Website · Kern umgesetzt und ausgeliefert (26.10.)
+10 -2
View File
@@ -1,9 +1,17 @@
# Projektstand
Stand: 26.10.2026 · automatischer PipelineManager-Testdeploy erfolgreich (erster Nachweis: Lauf 4656, Commit `e7f79e4`) · 285 Feature-Tests grün
Stand: 26.10.2026 · Mandantenabschluss auf `feature/mandanten-abschluss` umgesetzt; abschließender Pipeline-Testdeploy noch ausstehend. Bisheriger Serverstand: `86374b1`.
> Dieses Dokument ist der Einstieg für jede neue Arbeitssitzung. Bitte bei größeren Änderungen fortschreiben (Abschnitte „Fertig“, „Offen“, „Nächste Schritte“).
**Fachliche Funktionsdokumentation (26.10.2026):** [docs/architecture/README.md](architecture/README.md) führt durch die vorhandenen Funktionen nach fachlichen Ebenen und Bereichen. [Planung und offene Punkte](architecture/planung-und-offene-punkte.md) trennt geplante Erweiterungen, Optionen und noch nötige Inbetriebnahme. Abgeglichen mit dem lokalen Anwendungsstand; keine Auslieferung durch diese Dokumentationsarbeit. Neu festgehaltene offene Abweichung: Sonderangebote können im aktuellen Preisrechner die absolute Mindestnächtezahl umgehen (Details: [Preise und Angebote](architecture/preise-und-angebote.md)).
**Mandantenabschluss (26.10.):** Beide Themes nutzen Website-Logo/Favicon und die gewählte Bildwelt, auch für Bildplatzhalter. HTML- und Textmails tragen den eigenen Namen; HTML bettet das Dokumentlogo ein. Vertragsdateien liegen getrennt unter `contracts/tenants/<id>/bookings/<id>/`; Export/Löschung berücksichtigen Website-Medien, Bildkonvertierungen und Dokumentversionen. Bestehende flache Vertragsdateien bleiben lesbar; mehrdeutig von mehreren Mandanten referenzierte Altdateien stoppen die Löschung. Marken-Uploads erlauben PNG/WebP bzw. PNG/ICO; SVG wird ausschließlich aus geprüften Repository-Quellen importiert. `sites:import-stommer-brand <site-id>` übernimmt die bisherige Marke nur für Stommer, wiederholbar und ohne vorhandene Uploads zu ersetzen.
**Abnahme lokal:** 303 Feature-Tests / 1409 Assertions grün (18 zusätzliche Fälle), beide Themes mit `themes:check` geprüft, `image-worlds:check` erfolgreich, Vite-Build und Pint erfolgreich. Die leere Unit-Suite aus `phpunit.xml` entfernt; der normale PHPUnit-Aufruf funktioniert damit wieder. Keine neue Migration, Abhängigkeit oder lokale Datenbank. Die bestehenden Nutzerdateien unter `styles/` und ein parallel entstandener Ordner `docs/architecture/` bleiben unberührt.
**Verbindliche Umgebung:** Test unter **https://www.stommer.info** (auch `stommer.info`), Serverpfad **`test.fewo-stommer.de/`**, nur per SSH verwaltet. `dev.fewo-stommer.de/` existiert nicht (SSH-Prüfung und Bestätigung Lars 26.10.). Der Produktionsordner ist höchstens eine leere Vorbereitung; Produktion bleibt gesperrt. Vor deren Aufbau ist eine eigene MariaDB-Datenbank zusätzlich zur Testdatenbank einzurichten, keine Datenbank pro Mandant. Weiterhin bestehender PipelineManager-Ablauf: `develop` → Staging; kein zusätzlicher MariaDB-Testjob und keine neue lokale Umgebung.
## 1. Fertig (umgesetzt, getestet, auf stommer.info)
**Vermietung**
@@ -167,7 +175,7 @@ ### Phase 7: Kern umgesetzt und ausgeliefert
### Ebenfalls offen
- **Theme-Teil von Phase 6:** Favicon und `partials/brand` in beiden Themes auf `$theme->brand()` bzw. Plätze umstellen, Seebads `motifs/`-Ordner gegen die Bildwelt tauschen. Steht als Aufgabe in ZUSAMMENARBEIT.md §6 und gehört der Theme-Sitzung.
- **Theme-Teil von Phase 6:** im Mandantenabschluss umgesetzt; bestehende Stommer-Marke nach Auslieferung einmal mit `sites:import-stommer-brand <site-id>` übernehmen. Abnahme und Deploymentnachweis stehen am Dokumentanfang.
- **Subscription und Abrechnung** – nicht Teil des Mandanten-Plans (§9 schließt sie aus). `service_usages` liegt als Grundlage bereit und zählt nichts.
- **Zertifikatsfrage bei Strato:** Ob eine Domain eines Mandanten aufgeschaltet werden kann **und** ein Zertifikat bekommt. Eine Subdomain bekommt keines. Davon hängt ab, ob „Mandant bringt seine Domain mit“ auf diesem Hosting trägt – das ist keine Code-Frage.
+1
View File
@@ -84,6 +84,7 @@ ## 6. Änderungsprotokoll Vorlagen-Vertrag
| Datum | Änderung | Betrifft |
|---|---|---|
| 26.10.2026 | **Mandantenabschluss:** Beide Themes beziehen Logo und Favicon ausschließlich aus der Website-Marke; ohne Marke bleibt die Darstellung neutral. Dekoration und Bild-Platzhalter kommen aus Bildwelt-Plätzen. `partials/brand` bleibt als kompatible Platz-Zuordnung erhalten; Seebads `partials/motif` nutzt die Bildwelt-API. Bestehende Stommer-Marken werden vor Aktivierung ausdrücklich für diese Website importiert. | layouts/app, partials/brand, partials/logo, partials/motif, partials/image, header |
| 22.10.2026 | `theme-base.css` (Schriften, Token-Mapping, Basis-Klassen) von `theme.css` getrennt – Child-Themes importieren `theme-base.css` | theme.css |
| 22.10.2026 | Markengrafiken: `@include('theme::partials.brand', ['name' => 'mark', 'class' => '…'])` (mark, logo, wave-divider, icon-apartment/-sea/-terrace/-location); Farben über `--brand-navy/-teal/-wave/-sun` (navy = Textfarbe) | header, footer, facts, location, image |
| 22.10.2026 | `hero`: `$featuredOffer` (wichtigstes hervorgehobenes Angebot oder null) | sections/hero |
-3
View File
@@ -5,9 +5,6 @@
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory>tests/Feature</directory>
</testsuite>
+1 -1
View File
@@ -61,7 +61,7 @@ storage = "storage"
[targets.staging]
branch = "develop"
path = "test.fewo-stommer.de"
url = "https://stommer.info"
url = "https://www.stommer.info"
php = "/opt/RZphp84/bin/php-cli"
enabled = true
@@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" role="img" aria-label="Ferienwohnung">
<title>Ferienwohnung</title>
<circle cx="88" cy="62" r="15" fill="var(--brand-sun, #F2C27A)"/>
<path fill="var(--brand-navy, #0B2E55)" d="M12 64 L52 34 L68 46 L68 36 L76 36 L76 52 C84 60 92 66 104 70 L94 70 C86 68 78 62 72 57 L52 42 L16 68 C13 70 10 66 12 64 Z"/>
<g fill="var(--brand-navy, #0B2E55)"><rect x="45" y="50" width="6" height="6" rx="1"/><rect x="53" y="50" width="6" height="6" rx="1"/><rect x="45" y="58" width="6" height="6" rx="1"/><rect x="53" y="58" width="6" height="6" rx="1"/></g>
<rect x="82" y="74" width="30" height="3.5" rx="1.75" fill="var(--brand-sun, #F2C27A)"/>
<path fill="var(--brand-teal, #0286A2)" d="M6 92 C18 80 32 74 46 75 C62 76 74 86 96 84 C86 92 74 94 62 92 C48 90 36 83 22 84 C16 85 10 88 6 92 Z"/>
<path fill="var(--brand-wave, #6DBFC2)" d="M12 100 C22 94 32 92 42 93 C54 94 62 100 76 100 C68 104 58 104 50 103 C40 101 30 98 12 100 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 1000 B

@@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" role="img" aria-label="Lage">
<title>Lage</title>
<defs><clipPath id="icon-location-inner"><circle cx="60" cy="46" r="28"/></clipPath></defs>
<path fill="var(--brand-navy, #0B2E55)" fill-rule="evenodd" d="M60 6 C82 6 98 22 98 44 C98 66 74 88 60 112 C46 88 22 66 22 44 C22 22 38 6 60 6 Z M60 18 C45.6 18 34 29.6 34 44 C34 58.4 45.6 70 60 70 C74.4 70 86 58.4 86 44 C86 29.6 74.4 18 60 18 Z"/>
<g clip-path="url(#icon-location-inner)">
<circle cx="66" cy="46" r="13" fill="var(--brand-sun, #F2C27A)"/>
<path fill="var(--brand-teal, #0286A2)" d="M30 54 C40 46 52 44 62 47 C72 50 80 54 92 50 L92 58 C82 62 72 60 62 56 C52 52 42 52 30 60 Z"/>
<path fill="var(--brand-wave, #6DBFC2)" d="M30 64 C40 58 50 57 60 60 C70 63 80 64 92 60 L92 68 C80 72 70 70 60 67 C50 64 40 64 30 70 Z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 871 B

@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" role="img" aria-label="Ostsee">
<title>Ostsee</title>
<path fill="var(--brand-teal, #0286A2)" d="M8 76 C20 60 36 52 52 56 C66 60 76 72 90 68 C98 66 102 58 98 50 C94 44 86 44 84 50 C88 48 92 52 90 56 C86 62 76 58 74 48 C72 38 82 30 92 32 C106 34 114 48 110 62 C106 78 88 86 72 82 C58 78 48 66 34 66 C24 66 16 70 8 76 Z"/>
<path fill="var(--brand-wave, #6DBFC2)" d="M10 90 C22 80 36 76 50 78 C64 80 76 90 104 82 C96 92 82 96 68 94 C54 92 42 86 30 86 C22 86 16 88 10 90 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 547 B

@@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" role="img" aria-label="Terrasse und Strand">
<title>Terrasse und Strand</title>
<defs><clipPath id="icon-terrace-sun"><rect x="70" y="20" width="40" height="34"/></clipPath></defs>
<circle cx="90" cy="46" r="15" fill="var(--brand-sun, #F2C27A)" clip-path="url(#icon-terrace-sun)"/>
<rect x="72" y="56" width="38" height="3" rx="1.5" fill="var(--brand-sun, #F2C27A)"/><rect x="80" y="63" width="22" height="3" rx="1.5" fill="var(--brand-sun, #F2C27A)"/>
<path fill="var(--brand-navy, #0B2E55)" d="M14 44 C18 30 30 22 44 22 C58 22 70 30 74 44 C68 40 62 40 56 42 C52 38 48 37 44 37 C40 37 36 38 32 42 C26 40 20 40 14 44 Z"/>
<rect x="42.5" y="36" width="3.5" height="38" fill="var(--brand-navy, #0B2E55)"/>
<path fill="var(--brand-navy, #0B2E55)" d="M24 52 L30 52 L44 70 L66 70 C68 70 69 72 68 74 L34 74 L28 84 L24 84 L30 73 Z M58 74 L62 74 L66 84 L62 84 Z"/>
<path fill="var(--brand-teal, #0286A2)" d="M8 94 C24 86 42 84 60 86 C78 88 92 88 112 82 C100 92 82 96 64 95 C46 94 28 90 8 94 Z"/>
<path fill="var(--brand-wave, #6DBFC2)" d="M14 102 C30 97 46 96 62 98 C76 100 88 100 104 97 C94 103 80 105 66 104 C50 103 32 100 14 102 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

+5
View File
@@ -2,6 +2,11 @@
"name": "Ostsee",
"description": "Bänder, Vignetten und Ornamente der Ostseeküste: Sonne, Seebrücke, Möwen, Molli.",
"slots": {
"placeholder": "vignette-strand",
"icon-apartment": "icon-apartment",
"icon-sea": "icon-sea",
"icon-terrace": "icon-terrace",
"icon-location": "icon-location",
"divider": "band-sonne",
"closing": "band-seebruecke",
"crest": "gaube",
@@ -20,8 +20,9 @@
<meta property="og:image" content="{{ $ogImage }}">
@endisset
<link rel="canonical" href="{{ url()->current() }}">
<link rel="icon" href="{{ asset('brand/favicon.svg') }}" type="image/svg+xml">
<link rel="apple-touch-icon" href="{{ asset('brand/apple-touch-icon.png') }}">
@if ($favicon = $theme->brand('favicon'))
<link rel="icon" href="{{ $favicon }}">
@endif
@if ($theme->isPreview || ! app()->isProduction())
<meta name="robots" content="noindex">
@endif
@@ -1,16 +1,8 @@
{{--
Inline brand graphic from public/brand/<name>.svg (mark, logo, wave-divider, icon-apartment, icon-sea,
icon-terrace, icon-location). Inline, so the colours follow the CSS variables --brand-navy/-teal/-wave/-sun
(theme-base.css maps navy to the text colour, so it stays visible in dark appearances).
Variables: $name, $class (optional), $label (optional; without it the graphic is decorative).
--}}
@php
static $brandSvgs = [];
$brandSvgs[$name] ??= is_file(public_path("brand/{$name}.svg")) ? file_get_contents(public_path("brand/{$name}.svg")) : '';
$brandUid = 'b'.\Illuminate\Support\Str::lower(\Illuminate\Support\Str::random(6));
$brandSvg = preg_replace(['/\s(role|aria-label)="[^"]*"/', '/<title>.*?<\/title>/s'], '', $brandSvgs[$name]);
$brandSvg = preg_replace(['/id="([^"]+)"/', '/url\(#([^)]+)\)/'], ['id="$1-'.$brandUid.'"', 'url(#$1-'.$brandUid.')'], $brandSvg);
$brandAttributes = 'class="'.e($class ?? '').'" '.(isset($label) ? 'role="img" aria-label="'.e($label).'"' : 'aria-hidden="true" focusable="false"');
$brandSvg = preg_replace('/<svg\s/', '<svg '.$brandAttributes.' ', $brandSvg, 1);
@endphp
{!! $brandSvg !!}
{{-- Identity comes from the website, decoration from picture-world slots. --}}
@if (in_array($name, ['mark', 'logo'], true))
@if ($logo = $theme->brand('logo'))
<img src="{{ $logo }}" alt="{{ $label ?? '' }}" class="{{ $class ?? '' }}" decoding="async">
@endif
@else
{!! $theme->motif($name === 'wave-divider' ? 'divider' : $name, $class ?? null, $label ?? null) !!}
@endif
@@ -3,8 +3,7 @@
<a href="{{ route('home') }}" class="flex items-center gap-3 leading-tight" aria-label="{{ $theme->site->name }} – Startseite">
@include('theme::partials.brand', ['name' => 'mark', 'class' => 'h-11 w-auto shrink-0 sm:h-12'])
<span class="flex flex-col">
<span class="font-display text-[1.875rem] font-semibold tracking-wide">{{ str($theme->site->name)->afterLast(' ') }}</span>
<span class="text-[11px] tracking-[0.24em] text-muted uppercase">Ferienwohnung · Kühlungsborn</span>
<span class="font-display text-[1.875rem] font-semibold tracking-wide">{{ $theme->site->name }}</span>
</span>
</a>
@@ -11,6 +11,6 @@
class="{{ $class ?? '' }}">
@else
<div class="{{ $class ?? '' }} flex items-center justify-center bg-surface" role="img" aria-label="Bild folgt">
<img src="{{ asset('brand/coastal-illustration-1200.webp') }}" alt="" loading="lazy" decoding="async" class="h-full max-h-full w-full object-contain p-6 opacity-90">
{!! $theme->motif('placeholder', 'h-full max-h-full w-full p-6 opacity-90') !!}
</div>
@endif
+2 -2
View File
@@ -22,8 +22,8 @@ ## Gestaltung
## Bildwelt
Grafiken liegen in `motifs/` (Quelle: `styles/satz3/svg/`) und werden nur über Plätze eingebunden:
`@include('theme::partials.motif', ['slot' => 'divider', 'class' => '…'])`. Plätze: `divider`, `closing`, `crest` (Rundbogengaube), `railing` (Balkongeländer), `bracket` (Kopfband), `gulls`, `vignette.beach|pier|train|bike|forest`. Die Bildmarke des Logos kommt als Bild über `partials/logo` (Illustration – als Inline-SVG zu groß). Die Zuordnung Platz → Datei steht nur in `partials/motif.blade.php`, damit ein späteres Bildwelt-System (MANDANTEN-ANFORDERUNGEN A18/A19) sie ersetzen kann. Farben über `--brand-navy` (= Textfarbe), `--brand-paper` (= Flächen), `--brand-teal`, `--brand-wave`, `--brand-sun`, `--brand-reed`, `--brand-brick`.
Die Website waehlt ihre Bildwelt; eine Wohnung kann sie ueberschreiben. `partials/motif` delegiert an `$theme->motif()`. Dekoration kommt ausschliesslich aus `resources/image-worlds/<key>/`. Logo und Favicon kommen aus der Website-Marke. Die bisherigen Dateien in `img/` und `motifs/` bleiben Quellen; die Vorlagen verwenden sie nicht mehr direkt.
## Eigene Vorlagen
@@ -20,8 +20,9 @@
<meta property="og:image" content="{{ $ogImage }}">
@endisset
<link rel="canonical" href="{{ url()->current() }}">
<link rel="icon" href="{{ Vite::asset('resources/themes/seebad/img/favicon.svg') }}" type="image/svg+xml">
<link rel="apple-touch-icon" href="{{ Vite::asset('resources/themes/seebad/img/apple-touch-icon.png') }}">
@if ($favicon = $theme->brand('favicon'))
<link rel="icon" href="{{ $favicon }}">
@endif
@if ($theme->isPreview || ! app()->isProduction())
<meta name="robots" content="noindex">
@endif
@@ -1,7 +1,4 @@
{{--
Picture mark of the logo (styles/satz4: traced master SVG, WebP renditions for the web).
Variables: $class, $sizes (default: 10rem), $label (optional; without it the mark is decorative next to the name).
--}}
<img src="{{ Vite::asset('resources/themes/seebad/img/logo-bildmarke-360.webp') }}"
srcset="{{ Vite::asset('resources/themes/seebad/img/logo-bildmarke-360.webp') }} 360w, {{ Vite::asset('resources/themes/seebad/img/logo-bildmarke-720.webp') }} 720w, {{ Vite::asset('resources/themes/seebad/img/logo-bildmarke-1440.webp') }} 1440w"
sizes="{{ $sizes ?? '10rem' }}" width="360" height="154" alt="{{ $label ?? '' }}" decoding="async" class="{{ $class ?? '' }}">
{{-- A website without a logo never inherits another landlord's identity. --}}
@if ($logo = $theme->brand('logo'))
<img src="{{ $logo }}" alt="{{ $label ?? '' }}" decoding="async" class="{{ $class ?? '' }}">
@endif
@@ -1,31 +1,2 @@
{{--
Inline graphic of the theme's picture world ("Bildwelt", docs/DESIGN-KONZEPT.md §7, MANDANTEN-ANFORDERUNGEN A18/A19).
Templates ask for a slot, never for a file, so a later picture-world system can replace the mapping below.
Variables: $slot (divider, closing, crest, railing, bracket, gulls, vignette.beach|pier|train|bike|forest), $class (optional),
$label (optional; without it the graphic is decorative).
--}}
@php
$motifFiles = [
'divider' => 'band-sonne',
'closing' => 'band-seebruecke',
'crest' => 'gaube',
'railing' => 'gelaender',
'bracket' => 'kopfband',
'gulls' => 'moewen',
'vignette.beach' => 'vignette-strand',
'vignette.pier' => 'vignette-seebruecke',
'vignette.train' => 'vignette-molli',
'vignette.bike' => 'vignette-rad',
'vignette.forest' => 'vignette-wald',
];
static $motifSvgs = [];
$motifFile = $motifFiles[$slot] ?? null;
$motifPath = $motifFile ? resource_path("themes/seebad/motifs/{$motifFile}.svg") : null;
$motifSvgs[$slot] ??= $motifPath && is_file($motifPath) ? file_get_contents($motifPath) : '';
$motifUid = 'm'.\Illuminate\Support\Str::lower(\Illuminate\Support\Str::random(6));
$motifSvg = preg_replace(['/\s(role|aria-label|aria-hidden)="[^"]*"/', '/<title>.*?<\/title>/s'], '', $motifSvgs[$slot]);
$motifSvg = preg_replace(['/id="([^"]+)"/', '/url\(#([^)]+)\)/'], ['id="$1-'.$motifUid.'"', 'url(#$1-'.$motifUid.')'], $motifSvg);
$motifAttributes = 'class="'.e($class ?? '').'" '.(isset($label) ? 'role="img" aria-label="'.e($label).'"' : 'aria-hidden="true" focusable="false"');
$motifSvg = preg_replace('/<svg\s/', '<svg '.$motifAttributes.' ', $motifSvg, 1);
@endphp
{!! $motifSvg !!}
{{-- Decoration follows the website, overridden by the current apartment. --}}
{!! $theme->motif($slot, $class ?? null, $label ?? null) !!}
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$booking->website()" :message="$message ?? null">
# Bald sind Sie an der Ostsee!
Guten Tag {{ $booking->guest->full_name }},
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$booking->website()" :message="$message ?? null">
# Ihre Buchung ist bestätigt!
Guten Tag {{ $booking->guest->full_name }},
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$booking->website()" :message="$message ?? null">
# Ihre Anfrage {{ $booking->reference }}
Guten Tag {{ $booking->guest->full_name }},
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$channel->property?->site" :message="$message ?? null">
# Mögliche Doppelbuchung
Beim Kalender-Abgleich mit **{{ $channel->name }}** wurde eine neue Belegung gefunden, die sich mit einer bestehenden Belegung überschneidet:
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$channel->property?->site" :message="$message ?? null">
# Kalender-Abgleich gestört
Der Kalender von **{{ $channel->name }}** konnte seit
+1 -1
View File
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="($tasks[0] ?? null)?->channel?->property?->site" :message="$message ?? null">
# {{ $reminder ? 'Noch offen: ' : '' }}Bitte Portal-Kalender anpassen
@if ($reminder)
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$guest->website()" :message="$message ?? null">
# Bitte bestätigen Sie Ihre Anmeldung
Guten Tag {{ $guest->full_name }},
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$booking->website()" :message="$message ?? null">
# Neue Anfrage {{ $booking->reference }}
**{{ $booking->guest->full_name }}** möchte die **{{ $booking->property->name }}** buchen.
+1 -1
View File
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$review->property?->site" :message="$message ?? null">
# Neue Bewertung
**{{ $review->display_name }}** hat {{ $review->rating }} von 5 Sternen vergeben.
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$booking->website()" :message="$message ?? null">
@if ($accepted)
# Angebot angenommen
+1 -1
View File
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$booking->website()" :message="$message ?? null">
# Ihr Angebot für die {{ $booking->property->name }}
Guten Tag {{ $booking->guest->full_name }},
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$booking->website()" :message="$message ?? null">
@if ($kind === \App\Mail\PaymentReminder::BALANCE_REQUEST)
# Ihre Restzahlung
+1 -1
View File
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$portalEmail->channel?->property?->site" :message="$message ?? null">
# {{ $portalEmail->status->getLabel() }}
Zur E-Mail von **{{ $portalEmail->channel->name }}** („{{ $portalEmail->subject }}“, eingegangen {{ $portalEmail->received_at->format('d.m.Y, H:i') }} Uhr):
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$booking->website()" :message="$message ?? null">
# {{ $booking->offer_version > 0 ? 'Angebot abgelaufen' : 'Vormerkung abgelaufen' }}
Die Anfrage **{{ $booking->reference }}** von {{ $booking->guest->full_name }} ({{ $booking->arrival->format('d.m.Y') }} – {{ $booking->departure->format('d.m.Y') }}) {{ $booking->offer_version > 0 ? 'wurde vom Gast nicht rechtzeitig angenommen' : 'wurde nicht rechtzeitig beantwortet' }}. Der Zeitraum ist im Kalender wieder frei.
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$booking->website()" :message="$message ?? null">
# Vielen Dank für Ihre Anfrage!
Guten Tag {{ $booking->guest->full_name }},
@@ -1,4 +1,4 @@
<x-mail::message>
<x-mail::message :site="$booking->website()" :message="$message ?? null">
# Wie war Ihr Aufenthalt?
Guten Tag {{ $booking->guest->full_name }},
+27
View File
@@ -0,0 +1,27 @@
@props(['site' => null, 'message' => null])
@php
$name = $site?->name ?: (config('fewo.owner.name') ?: 'Vermietung');
$origin = $site?->origin() ?: config('app.url');
$logo = $site?->brandPath(\App\Models\Site::BRAND_DOCUMENT_LOGO);
@endphp
<x-mail::layout>
<x-slot:header>
<x-mail::header :url="$origin">{{ $name }}</x-mail::header>
</x-slot:header>
@if ($logo && $message instanceof \Illuminate\Mail\Message)
<p><img src="{{ $message->embed($logo) }}" alt="{{ $name }}" style="max-width: 240px; max-height: 100px;"></p>
@endif
{!! $slot !!}
@isset($subcopy)
<x-slot:subcopy>
<x-mail::subcopy>{!! $subcopy !!}</x-mail::subcopy>
</x-slot:subcopy>
@endisset
<x-slot:footer>
<x-mail::footer>© {{ date('Y') }} {{ $name }}. Alle Rechte vorbehalten.</x-mail::footer>
</x-slot:footer>
</x-mail::layout>
+23
View File
@@ -0,0 +1,23 @@
@props(['site' => null, 'message' => null])
@php
$name = $site?->name ?: (config('fewo.owner.name') ?: 'Vermietung');
$origin = $site?->origin() ?: config('app.url');
@endphp
<x-mail::layout>
<x-slot:header>
<x-mail::header :url="$origin">{{ $name }}</x-mail::header>
</x-slot:header>
{{ $slot }}
@isset($subcopy)
<x-slot:subcopy>
<x-mail::subcopy>{{ $subcopy }}</x-mail::subcopy>
</x-slot:subcopy>
@endisset
<x-slot:footer>
<x-mail::footer>© {{ date('Y') }} {{ $name }}. Alle Rechte vorbehalten.</x-mail::footer>
</x-slot:footer>
</x-mail::layout>
+178
View File
@@ -0,0 +1,178 @@
<?php
namespace Tests\Feature;
use App\Enums\UserRole;
use App\Filament\Resources\Sites\Pages\EditSite;
use App\ImageWorlds\ImageWorldRegistry;
use App\Mail\BookingConfirmed;
use App\Models\Booking;
use App\Models\Page;
use App\Models\Property;
use App\Models\Site;
use App\Models\Tenant;
use App\Models\User;
use App\Tenancy\TenantContext;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use PHPUnit\Framework\Attributes\TestWith;
use Tests\TestCase;
class TenantBrandRenderingTest extends TestCase
{
use RefreshDatabase;
#[TestWith(['ostsee-licht'])]
#[TestWith(['seebad'])]
public function test_both_themes_show_only_the_current_websites_brand(string $theme): void
{
Storage::fake('public');
$this->withoutVite();
$first = $this->website('Nordhaus', 'nord.test', $theme);
$second = $this->website('Südheim', 'sued.test', $theme);
$first->addMedia(UploadedFile::fake()->image('nord-logo.png'))->toMediaCollection(Site::BRAND_LOGO);
$first->addMedia(UploadedFile::fake()->image('nord-icon.png'))->toMediaCollection(Site::BRAND_FAVICON);
$second->addMedia(UploadedFile::fake()->image('sued-logo.png'))->toMediaCollection(Site::BRAND_LOGO);
$second->addMedia(UploadedFile::fake()->image('sued-icon.png'))->toMediaCollection(Site::BRAND_FAVICON);
$this->get('https://nord.test/')->assertOk()->assertSee('nord-logo.png')->assertSee('nord-icon.png')
->assertDontSee('sued-logo.png')->assertDontSee('sued-icon.png');
$this->get('https://sued.test/')->assertOk()->assertSee('sued-logo.png')->assertSee('sued-icon.png')
->assertDontSee('nord-logo.png')->assertDontSee('nord-icon.png');
}
#[TestWith(['ostsee-licht'])]
#[TestWith(['seebad'])]
public function test_a_website_without_a_brand_does_not_inherit_stommers_identity(string $theme): void
{
$this->withoutVite();
$this->website('Berghaus Alpenblick', 'berge.test', $theme);
$this->get('https://berge.test/')->assertOk()->assertSee('Berghaus Alpenblick')
->assertDontSee('logo-bildmarke')->assertDontSee('brand/favicon')->assertDontSee('img/favicon')
->assertDontSee('Ferienwohnung · Kühlungsborn');
}
#[TestWith(['ostsee-licht'])]
#[TestWith(['seebad'])]
public function test_the_selected_picture_world_supplies_decoration_and_placeholder_in_both_themes(string $theme): void
{
$this->withoutVite();
$directory = storage_path('framework/testing/brand-worlds');
File::ensureDirectoryExists($directory.'/berge/svg');
File::put($directory.'/berge/world.json', json_encode([
'name' => 'Berge', 'slots' => ['divider' => 'berg', 'placeholder' => 'berg'],
]));
File::put($directory.'/berge/svg/berg.svg', '<svg viewBox="0 0 10 10" data-world="berge"><path d="M0 10L5 0L10 10"/></svg>');
config(['image-worlds.paths' => [$directory], 'image-worlds.default' => null]);
app()->forgetInstance(ImageWorldRegistry::class);
$site = $this->website('Berghaus', 'berge.test', $theme);
$site->update(['image_world' => 'berge']);
try {
$this->get('https://berge.test/')->assertOk()->assertSee('data-world="berge"', escape: false)
->assertDontSee('coastal-illustration')->assertDontSee('brand/mark.svg');
} finally {
File::deleteDirectory($directory);
}
}
public function test_booking_mail_embeds_only_the_logo_of_its_website(): void
{
Storage::fake('public');
$first = $this->website('Nordhaus', 'nord.test', 'seebad');
$second = $this->website('Südheim', 'sued.test', 'seebad');
$firstLogo = $first->addMedia(UploadedFile::fake()->image('nord-mail.png', 300, 100))->toMediaCollection(Site::BRAND_DOCUMENT_LOGO);
$secondLogo = $second->addMedia(UploadedFile::fake()->image('sued-mail.png', 400, 150))->toMediaCollection(Site::BRAND_DOCUMENT_LOGO);
app(TenantContext::class)->run($first->tenant, function () use ($first, $firstLogo, $secondLogo): void {
$booking = Booking::factory()->for($first->primaryProperty())->create(['deposit_due_on' => now()->addWeek()]);
$mail = new BookingConfirmed($booking);
$html = $mail->render();
$this->assertSame(1, preg_match('/src="data:image\/png;base64,([^"]+)"/s', $html, $image));
$this->assertSame(File::get($firstLogo->getPath()), base64_decode($image[1], strict: true));
$this->assertNotSame(File::get($secondLogo->getPath()), base64_decode($image[1], strict: true));
$this->assertStringContainsString('Nordhaus', $html);
$this->assertStringNotContainsString('Südheim', $html);
$this->assertStringNotContainsString('Ferienwohnung Stommer', $html);
$mail->assertSeeInText('Nordhaus');
$mail->assertDontSeeInText('Ferienwohnung Stommer');
});
}
public function test_the_legacy_brand_import_preserves_uploads_and_refuses_other_landlords(): void
{
Storage::fake('public');
$site = $this->website('Stommer', 'stommer.test', 'seebad');
$site->tenant->update(['slug' => 'stommer']);
$custom = $site->addMedia(UploadedFile::fake()->image('eigenes-logo.png'))->toMediaCollection(Site::BRAND_LOGO);
$other = $this->website('Anderer Vermieter', 'andere.test', 'seebad');
$this->artisan('sites:import-stommer-brand', ['site' => $site->id])->assertSuccessful();
$this->artisan('sites:import-stommer-brand', ['site' => $site->id])->assertSuccessful();
$this->artisan('sites:import-stommer-brand', ['site' => $other->id])->assertFailed();
$this->assertSame($custom->id, $site->fresh()->getFirstMedia(Site::BRAND_LOGO)->id);
$this->assertCount(3, $site->fresh()->media);
$this->assertCount(0, $other->fresh()->media);
}
#[TestWith(['logo'])]
#[TestWith(['favicon'])]
public function test_the_admin_rejects_unchecked_svg_uploads(string $field): void
{
Storage::fake('public');
$site = $this->website('Nordhaus', 'nord.test', 'seebad');
$user = User::factory()->role(UserRole::Admin)->create();
$user->tenants()->syncWithoutDetaching([$site->tenant_id => ['role' => UserRole::Admin->value]]);
app(TenantContext::class)->set($site->tenant);
$this->actingAs($user);
$upload = UploadedFile::fake()->createWithContent('unsicher.svg', '<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>');
Livewire::test(EditSite::class, ['record' => $site->getRouteKey()])
->fillForm([$field => [$upload]])->call('save')->assertHasFormErrors([$field]);
$this->assertCount(0, $site->fresh()->media);
}
#[TestWith(['logo'])]
#[TestWith(['favicon'])]
#[TestWith(['document_logo'])]
public function test_the_admin_saves_brand_images_on_the_public_disk(string $field): void
{
Storage::fake('public');
$site = $this->website('Nordhaus', 'nord.test', 'seebad');
$user = User::factory()->role(UserRole::Admin)->create();
$user->tenants()->syncWithoutDetaching([$site->tenant_id => ['role' => UserRole::Admin->value]]);
app(TenantContext::class)->set($site->tenant);
$this->actingAs($user);
Livewire::test(EditSite::class, ['record' => $site->getRouteKey()])
->fillForm([$field => [UploadedFile::fake()->image('marke.png')]])->call('save')->assertHasNoFormErrors();
$media = $site->fresh()->getFirstMedia($field);
$this->assertNotNull($media);
$this->assertSame('public', $media->disk);
$this->assertFileExists($media->getPath());
$this->assertStringContainsString('/storage/', $site->fresh()->brandUrl($field));
}
private function website(string $name, string $host, string $theme): Site
{
$tenant = Tenant::factory()->create(['name' => $name, 'owner_name' => $name]);
return app(TenantContext::class)->run($tenant, function () use ($name, $host, $theme): Site {
$site = Site::factory()->create(['name' => $name, 'domain' => $host, 'theme' => $theme, 'is_default' => true]);
Property::factory()->create(['site_id' => $site->id]);
Page::factory()->create(['site_id' => $site->id, 'slug' => Page::HOME, 'sections' => [
['type' => 'hero', 'data' => ['title' => $name]],
]]);
return $site;
});
}
}
+148
View File
@@ -0,0 +1,148 @@
<?php
namespace Tests\Feature;
use App\Documents\RentalContract;
use App\Models\Booking;
use App\Models\Property;
use App\Models\Site;
use App\Models\Tenant;
use App\Tenancy\TenantArchive;
use App\Tenancy\TenantContext;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use PHPUnit\Framework\Attributes\TestWith;
use Tests\TestCase;
use ZipArchive;
class TenantFilesTest extends TestCase
{
use RefreshDatabase;
#[TestWith([false])]
#[TestWith([true])]
public function test_equal_booking_numbers_do_not_overwrite_another_tenants_document(bool $draft): void
{
Storage::fake('local');
$first = $this->booking('Nordhaus');
$second = $this->booking('Südheim');
$contracts = app(RentalContract::class);
$firstPath = $contracts->generate($first, $draft);
$firstContent = Storage::disk('local')->get($firstPath);
$secondPath = $contracts->generate($second, $draft);
$this->assertSame($first->reference, $second->reference);
$this->assertNotSame($firstPath, $secondPath);
$this->assertSame($firstContent, Storage::disk('local')->get($firstPath));
Storage::disk('local')->assertExists($secondPath);
}
public function test_export_and_deletion_include_website_media_and_all_document_versions_only_of_that_tenant(): void
{
Storage::fake('public');
Storage::fake('local');
$gone = $this->booking('Geht');
$stays = $this->booking('Bleibt');
$site = $gone->website();
$otherSite = $stays->website();
$logo = $site->addMedia(UploadedFile::fake()->image('geht.png'))->toMediaCollection(Site::BRAND_LOGO);
$otherLogo = $otherSite->addMedia(UploadedFile::fake()->image('bleibt.png'))->toMediaCollection(Site::BRAND_LOGO);
$contracts = app(RentalContract::class);
$oldOffer = $contracts->generate($gone, draft: true);
$gone->update(['offer_version' => 2]);
$newOffer = $contracts->generate($gone, draft: true);
$contract = $contracts->generate($gone);
$otherContract = $contracts->generate($stays);
$otherBytes = Storage::disk('local')->get($otherContract);
$directory = storage_path('framework/testing/tenant-files');
try {
$archive = app(TenantArchive::class);
$path = $archive->export($site->tenant, $directory);
$zip = new ZipArchive;
$this->assertTrue($zip->open($path));
$this->assertNotFalse($zip->locateName('dateien/'.$logo->id.'-geht.png'));
$this->assertFalse($zip->locateName('dateien/'.$otherLogo->id.'-bleibt.png'));
foreach ([$oldOffer, $newOffer, $contract] as $document) {
$this->assertSame(Storage::disk('local')->get($document), $zip->getFromName('dateien/local/'.$document));
}
$this->assertFalse($zip->locateName('dateien/local/'.$otherContract));
$media = json_decode($zip->getFromName('daten/media.json'), true, flags: JSON_THROW_ON_ERROR);
$this->assertSame([$logo->id], array_column($media, 'id'));
$zip->close();
$archive->delete($site->tenant);
$this->assertFileDoesNotExist($logo->getPath());
$this->assertFileExists($otherLogo->getPath());
$this->assertDatabaseMissing('media', ['id' => $logo->id]);
$this->assertDatabaseHas('media', ['id' => $otherLogo->id]);
Storage::disk('local')->assertMissing([$oldOffer, $newOffer, $contract]);
$this->assertSame($otherBytes, Storage::disk('local')->get($otherContract));
} finally {
File::deleteDirectory($directory);
}
}
public function test_existing_document_paths_remain_readable_and_are_exported_and_deleted(): void
{
Storage::fake('local');
$booking = $this->booking('Altbestand');
$path = 'contracts/Mietvertrag-2026-0001.pdf';
Storage::disk('local')->put($path, '%PDF-alter-vertrag');
$booking->update(['contract_path' => $path]);
$directory = storage_path('framework/testing/legacy-tenant-files');
try {
$this->assertSame(Storage::disk('local')->path($path), app(RentalContract::class)->absolutePath($booking));
$archive = app(TenantArchive::class);
$zip = new ZipArchive;
$this->assertTrue($zip->open($archive->export($booking->tenant, $directory)));
$this->assertSame('%PDF-alter-vertrag', $zip->getFromName('dateien/local/'.$path));
$zip->close();
$archive->delete($booking->tenant);
Storage::disk('local')->assertMissing($path);
} finally {
File::deleteDirectory($directory);
}
}
public function test_ambiguous_legacy_documents_prevent_deletion_of_either_tenant(): void
{
Storage::fake('local');
$first = $this->booking('Erster');
$second = $this->booking('Zweiter');
$path = 'contracts/Mietvertrag-2026-0001.pdf';
Storage::disk('local')->put($path, '%PDF-mehrdeutig');
$first->update(['contract_path' => $path]);
$second->update(['contract_path' => $path]);
try {
app(TenantArchive::class)->delete($first->tenant);
$this->fail('Mehrdeutige Altbestände dürfen nicht automatisch gelöscht werden.');
} catch (\RuntimeException $exception) {
$this->assertSame('Vertragsdatei ist mehreren Mandanten zugeordnet: '.$path, $exception->getMessage());
}
$this->assertModelExists($first->tenant);
$this->assertModelExists($second->tenant);
Storage::disk('local')->assertExists($path);
}
private function booking(string $name): Booking
{
$tenant = Tenant::factory()->create(['name' => $name]);
return app(TenantContext::class)->run($tenant, function () use ($name): Booking {
$site = Site::factory()->create(['name' => $name]);
return Booking::factory()->for(Property::factory()->create(['site_id' => $site->id]))
->create(['reference' => '2026-0001', 'offer_version' => 1]);
});
}
}