Betreiber richtet Mandanten vollständig ein: Adressen, Sperrseite, Systemwerte

Ein neu angelegter Mandant war eine Sackgasse. Er bekam keine Website, also
keinen Host, also keine Adresse – und der Host wird im Mandanten-Admin
eingetragen, den er ohne Adresse nicht erreicht. „Im Admin öffnen" half
nicht: ohne Domain landete es beim Mandanten des aktuellen Hosts.

Einsprungsadressen gehören jetzt dem Betreiber, weil Webspace und Hosting
ihm gehören und ein Mandant nicht die Adresse eines anderen auf sich
zeigen lassen darf. Im Mandanten-Formular: Websites mit ihren Adressen.
Beim Anlegen entstehen Website, Host-Einträge und eine leere Startseite –
ohne Startseite antwortet die Website mit 404. Im Mandanten-Admin sind die
Adressen nur noch sichtbar, nicht änderbar. Die Domain beim Hoster auf das
Verzeichnis zu legen bleibt ein Schritt von Hand.

Gesperrter Mandant: statt 404 ein Hinweis mit Status 503, Text je Mandant
einstellbar. 503 hält die Seiten im Suchindex, weil die Sperre vorübergehend
ist.

Behoben: `URL::forceRootUrl(APP_URL)` zwang **alle** Links auf einen festen
Host. Mit einem Mandanten unsichtbar; mit zwei Domains hätte jeder interne
Link der zweiten Website auf die erste gezeigt. Der Ursprung ist jetzt der
Host der aufgelösten Website.

Neu: systemweite Einstellungen sind im Betreiber-Bereich änderbar
(Löschfristen, Bot-Schutz, Flutgrenze, Sicherungen, Portal-Fristen,
Versandweg, SMTP, harte Mail-Umleitung, Tokens). Leer heißt: der Wert der
.env gilt wieder – und zwar sofort, nicht erst beim nächsten Start.
Geheimnisse liegen verschlüsselt. Datenbank-Zugang und APP_KEY bleiben in
der .env, weil sie gebraucht werden, um die Datenbank zu öffnen und das
Gespeicherte zu entschlüsseln.

253 Feature-Tests grün.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Lars StommerandClaude Opus 5 committed 2026-10-24 10:20:18 +02:00
1 parent d9383cf3e5
commit 03ad4667ac
25 files changed
+997 -184

No files matched your search

+117
View File
@@ -0,0 +1,117 @@
<?php
namespace Tests\Feature;
use App\Filament\Operator\Pages\SystemSettingsPage;
use App\Models\SystemSetting;
use App\Models\Tenant;
use App\Models\User;
use App\Support\Settings;
use App\Support\SystemSettings;
use App\Tenancy\TenantConfig;
use App\Tenancy\TenantContext;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Livewire\Livewire;
use Tests\TestCase;
/**
* Settings of the whole installation, owned by the operator. They are the baseline a landlord may tighten
* but not exceed, so they have to win over the .env and lose to nobody's landlord.
*/
class SystemSettingsTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
SystemSettings::forget();
}
public function test_a_stored_value_wins_over_the_env_and_an_empty_one_gives_it_back(): void
{
config(['fewo.spam.total_per_hour' => 30]);
SystemSettings::save(['fewo.spam.total_per_hour' => '120']);
$this->assertSame(120, config('fewo.spam.total_per_hour'));
$this->assertSame(120, SystemSettings::get('fewo.spam.total_per_hour'));
SystemSettings::save(['fewo.spam.total_per_hour' => '']);
config(['fewo.spam.total_per_hour' => 30]);
SystemSettings::apply();
$this->assertSame(30, config('fewo.spam.total_per_hour'), 'Leer = der Wert der .env gilt wieder.');
$this->assertSame(0, SystemSetting::query()->count());
}
public function test_a_secret_is_stored_encrypted(): void
{
SystemSettings::save(['mail.mailers.smtp.password' => 'geheim']);
$stored = DB::table('system_settings')->where('key', 'mail.mailers.smtp.password')->first();
$this->assertNotSame('geheim', $stored?->value);
$this->assertTrue((bool) $stored?->is_secret);
$this->assertSame('geheim', SystemSettings::get('mail.mailers.smtp.password'));
}
/**
* The whole point of the ceiling: what the operator sets here binds every landlord.
*/
public function test_the_stored_limit_becomes_the_ceiling_for_a_landlord(): void
{
config(['fewo.guest_retention_years' => 10]);
SystemSettings::save(['fewo.guest_retention_years' => '4']);
$tenant = Tenant::factory()->create(['guest_retention_years' => 9]);
app(TenantContext::class)->set($tenant);
app(TenantConfig::class)->refresh();
$this->assertSame(4, config('fewo.guest_retention_years'), 'Der Mandant darf die Obergrenze nicht überschreiten.');
}
public function test_the_operator_edits_the_settings_and_a_landlords_administrator_cannot_reach_the_page(): void
{
$tenant = Tenant::factory()->create();
app(TenantContext::class)->set($tenant);
$admin = User::factory()->create();
$this->actingAs($admin)->get('/betreiber/einstellungen')->assertForbidden();
$admin->forceFill(['is_operator' => true])->saveQuietly();
$this->actingAs($admin);
Filament::setCurrentPanel('operator');
$this->get('/betreiber/einstellungen')->assertOk()->assertSee('Systemweite Einstellungen');
Livewire::test(SystemSettingsPage::class)
->set('data.fewo__spam__total_per_hour', '77')
->set('data.fewo__mail_redirect_to', 'auffang@example.com')
->call('save')
->assertHasNoErrors();
$this->assertSame(77, SystemSettings::get('fewo.spam.total_per_hour'));
$this->assertSame('auffang@example.com', config('fewo.mail_redirect_to'));
}
/**
* The hard redirect is the net that keeps a test server from writing to real guests. It is editable on
* purpose, so it must be obvious that emptying it hands the decision back to each landlord.
*/
public function test_emptying_the_hard_redirect_leaves_only_the_landlords_own_test_mode(): void
{
SystemSettings::save(['fewo.mail_redirect_to' => 'auffang@example.com']);
$live = Tenant::factory()->create(['operating_mode' => 'live', 'notification_emails' => 'wirt@example.com']);
app(TenantContext::class)->set($live);
$this->assertSame('auffang@example.com', Settings::mailRedirect());
SystemSettings::save(['fewo.mail_redirect_to' => '']);
$this->assertNull(Settings::mailRedirect(), 'Ohne harte Umleitung entscheidet der Mandant allein.');
}
}
+4 -2
View File
@@ -133,8 +133,10 @@ public function test_a_suspended_landlord_is_closed_except_for_the_operator(): v
app(TenantContext::class)->set($tenant);
$admin = User::factory()->create();
$this->get('/')->assertNotFound();
$this->actingAs($admin)->get('/admin')->assertNotFound();
// Visitors and the landlord's own people see a notice, not a dead link; 503 keeps the pages in the
// search index, because a suspended landlord is a temporary state.
$this->get('/')->assertStatus(503)->assertSee('nicht erreichbar');
$this->actingAs($admin)->get('/admin')->assertStatus(503);
$admin->forceFill(['is_operator' => true])->saveQuietly();
+159
View File
@@ -0,0 +1,159 @@
<?php
namespace Tests\Feature;
use App\Filament\Operator\Tenants\Pages\CreateTenant;
use App\Filament\Operator\Tenants\Pages\EditTenant;
use App\Models\Page;
use App\Models\Site;
use App\Models\Tenant;
use App\Models\User;
use App\Tenancy\TenantContext;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
/**
* Setting a landlord up is the operator's job: the hosting and the addresses are theirs. A landlord the
* operator created must be reachable straight away – otherwise nobody can get in to finish the job.
*/
class TenantProvisioningTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->withoutVite();
}
public function test_a_landlord_created_by_the_operator_is_reachable_at_once(): void
{
$this->asOperator();
Livewire::test(CreateTenant::class)
->fillForm([
'name' => 'Ferienhaus Düne',
'slug' => 'duene',
'is_active' => true,
'websites' => [['name' => 'Ferienhaus Düne', 'hosts' => ['duene.test', 'www.duene.test']]],
])
->call('create')
->assertHasNoErrors();
$tenant = Tenant::query()->where('slug', 'duene')->sole();
$site = Site::withoutGlobalScope('tenant')->where('tenant_id', $tenant->id)->sole();
$this->assertSame(['duene.test', 'www.duene.test'], $site->domains()->orderBy('host')->pluck('host')->all());
$this->assertSame('duene.test', $site->domain, 'Die erste Adresse ist die Hauptadresse.');
// Without a home page the website would answer 404 and the landlord could never get in.
$this->assertTrue(
app(TenantContext::class)->run($tenant, fn (): bool => $site->pages()->where('slug', Page::HOME)->exists()),
);
$this->get('http://duene.test/')->assertOk()->assertSee('Ferienhaus Düne');
$this->get('http://www.duene.test/')->assertOk();
}
public function test_a_suspended_landlord_shows_a_notice_instead_of_a_dead_link(): void
{
$tenant = Tenant::factory()->create(['is_active' => true]);
$site = $this->websiteFor($tenant, 'duene.test');
$this->assertNotNull($site);
Tenant::factory()->create(); // a second landlord, so hosts really decide
$this->get('http://duene.test/')->assertOk();
$tenant->update(['is_active' => false, 'suspended_message' => 'Die Vermietung pausiert bis Frühjahr.']);
$response = $this->get('http://duene.test/');
$response->assertStatus(503);
$response->assertSee('Die Vermietung pausiert bis Frühjahr.');
$response->assertSee('nicht erreichbar');
}
public function test_the_default_notice_applies_when_none_was_written(): void
{
$tenant = Tenant::factory()->create(['is_active' => false]);
$this->websiteFor($tenant, 'duene.test');
Tenant::factory()->create();
$this->get('http://duene.test/')->assertStatus(503)->assertSee('Bitte versuchen Sie es später noch einmal.');
}
/**
* Links on a website have to carry the address the visitor arrived on. APP_URL is a single value, so
* without this every link of a second landlord would point at the first landlord's host.
*/
public function test_links_carry_the_address_the_visitor_came_in_on(): void
{
config(['app.url' => 'https://erster.test']);
$first = Tenant::factory()->create();
$this->websiteFor($first, 'erster.test');
$second = Tenant::factory()->create();
$this->websiteFor($second, 'zweiter.test');
$html = $this->get('http://zweiter.test/')->assertOk()->getContent();
$this->assertStringNotContainsString('erster.test', (string) $html);
}
public function test_the_operator_adds_an_address_to_an_existing_landlord(): void
{
$tenant = Tenant::factory()->create();
$site = $this->websiteFor($tenant, 'duene.test');
Tenant::factory()->create();
$this->get('http://neu.duene.test/')->assertNotFound();
$this->asOperator();
Livewire::test(EditTenant::class, ['record' => $tenant->getRouteKey()])
->fillForm(['websites' => [[
'id' => $site->id,
'name' => $site->name,
'hosts' => ['duene.test', 'neu.duene.test'],
]]])
->call('save')
->assertHasNoErrors();
$this->get('http://neu.duene.test/')->assertOk();
$this->get('http://duene.test/')->assertOk();
}
private function asOperator(): void
{
$operator = User::factory()->create();
$operator->forceFill(['is_operator' => true])->saveQuietly();
$this->actingAs($operator);
Filament::setCurrentPanel('operator');
}
private function websiteFor(Tenant $tenant, string $host): Site
{
return app(TenantContext::class)->run($tenant, function () use ($tenant, $host): Site {
$site = Site::query()->create([
'tenant_id' => $tenant->id,
'name' => 'Website von '.$tenant->name,
'domain' => $host,
'is_default' => true,
'theme' => config('themes.base'),
]);
Page::query()->create([
'site_id' => $site->id,
'slug' => Page::HOME,
'title' => $site->name,
'sections' => [],
'is_published' => true,
]);
return $site;
});
}
}
+1
View File
@@ -117,6 +117,7 @@ public function test_the_operator_creates_a_landlord_in_the_operator_panel(): vo
'name' => 'Ferienhaus Düne',
'slug' => 'duene',
'is_active' => true,
'websites' => [['name' => 'Ferienhaus Düne', 'hosts' => ['duene.example']]],
'services.'.TenantServiceKey::PortalSync->value.'.is_enabled' => true,
'services.'.TenantServiceKey::PortalMail->value.'.is_enabled' => false,
])
+14 -8
View File
@@ -3,15 +3,14 @@
namespace Tests\Feature;
use App\Actions\SendOffer;
use App\Enums\UserRole;
use App\Filament\Resources\Sites\Pages\EditSite;
use App\Filament\Operator\Tenants\Pages\EditTenant;
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 Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Features\SupportTesting\Testable;
use Livewire\Livewire;
@@ -98,17 +97,24 @@ public function test_the_offer_link_uses_the_website_address(): void
}
/**
* Enters the further addresses through the real admin form, so the form's own defences are under test.
* Enters the addresses the way they are really entered: by the operator, on the landlord. The form's
* own defences are under test with them.
*
* @param list<string> $hosts
*/
private function editHosts(Site $site, array $hosts): Testable
{
app(TenantContext::class)->set($site->tenant);
$this->actingAs(User::factory()->role(UserRole::Admin)->create());
$operator = User::factory()->create();
$operator->forceFill(['is_operator' => true])->saveQuietly();
$this->actingAs($operator);
Filament::setCurrentPanel('operator');
return Livewire::test(EditSite::class, ['record' => $site->getRouteKey()])
->fillForm(['extra_hosts' => $hosts])
return Livewire::test(EditTenant::class, ['record' => $site->tenant->getRouteKey()])
->fillForm(['websites' => [[
'id' => $site->id,
'name' => $site->name,
'hosts' => [$site->domain, ...$hosts],
]]])
->call('save');
}