create(); app(TenantContext::class)->set($tenant); $channel = Channel::factory()->create(); $this->assertTrue($channel->importsOccupations()); $this->get(route('channels.feed', ['token' => $channel->export_token]))->assertOk(); $this->lock($tenant, TenantServiceKey::PortalSync); $this->assertFalse($channel->fresh()->importsOccupations()); $this->get(route('channels.feed', ['token' => $channel->export_token]))->assertNotFound(); } public function test_the_sync_command_skips_a_landlord_without_the_service(): void { $allowed = Tenant::factory()->create(['name' => 'Mit Dienst']); $locked = Tenant::factory()->create(['name' => 'Ohne Dienst']); app(TenantContext::class)->set($allowed); $allowedChannel = Channel::factory()->create(); app(TenantContext::class)->set($locked); $lockedChannel = Channel::factory()->create(); $this->lock($locked, TenantServiceKey::PortalSync); app(TenantContext::class)->forget(); $this->assertTrue($allowedChannel->fresh()->importsOccupations()); $this->assertFalse($lockedChannel->fresh()->importsOccupations()); } public function test_a_locked_service_closes_the_admin_screens_whatever_the_role_says(): void { $tenant = Tenant::factory()->create(); app(TenantContext::class)->set($tenant); $admin = User::factory()->role(UserRole::Admin)->create(); $this->actingAs($admin); $this->assertTrue(Gate::forUser($admin)->allows('viewAny', ChannelTask::class)); $this->lock($tenant, TenantServiceKey::PortalSync); $this->lock($tenant, TenantServiceKey::PortalMail); $this->assertFalse(Gate::forUser($admin)->allows('viewAny', ChannelTask::class)); $this->assertFalse(Gate::forUser($admin)->allows('viewAny', PortalEmail::class)); // The role itself is untouched – the landlord simply does not have the service. $this->assertTrue(Gate::forUser($admin)->allows('viewAny', Booking::class)); } public function test_the_mailbox_fast_path_stays_open_while_only_the_sync_is_locked(): void { $tenant = Tenant::factory()->create(); app(TenantContext::class)->set($tenant); $admin = User::factory()->role(UserRole::Admin)->create(); $this->lock($tenant, TenantServiceKey::PortalSync); $this->assertTrue(Gate::forUser($admin)->allows('viewAny', PortalEmail::class)); } public function test_the_system_page_shows_the_limits_and_stays_closed_for_a_landlords_administrator(): void { $tenant = Tenant::factory()->create(['name' => 'Beispiel GbR']); app(TenantContext::class)->set($tenant); config(['fewo.spam.total_per_hour' => 30, 'fewo.guest_retention_years' => 10]); $admin = User::factory()->role(UserRole::Admin)->create(); $this->actingAs($admin)->get('/betreiber/system')->assertForbidden(); $admin->forceFill(['is_operator' => true])->saveQuietly(); $this->actingAs($admin)->get('/betreiber/system') ->assertOk() ->assertSee('Beispiel GbR') ->assertSee('30 je Stunde') ->assertSee('10 Jahre'); } private function lock(Tenant $tenant, TenantServiceKey $service): void { $tenant->services()->updateOrCreate(['service' => $service->value], ['is_enabled' => false]); app(TenantFeatures::class)->forget($tenant); } }