refactor(settings): remove global appearance settings — tenant is sole source

Removes the global app_theme, app_theme_user and app_primary_color settings
from the admin/settings area and the underlying service/cache/API/i18n/docs
layers. The tenant columns (tenants.primary_color, default_theme,
allow_user_theme) become the single source of truth for appearance.
Branding helpers are tenant-only and fall back to a hardcoded 'light' theme
with no brand color when no tenant context is available (login, error,
pre-session pages). The APP_THEME env var is removed.

Scope:
- UI: Appearance tab gone from /admin/settings; tenant edit form drops the
  global-fallback color preview.
- Service: SettingsAppGateway no longer exposes setting-backed accessors
  for theme/user-theme/primary-color. Theme catalog utilities (listThemes,
  isAllowedTheme, normalizeTheme, resolveDefaultTheme) stay and are used
  across Tenant / Auth / User flows; resolveDefaultTheme now hardcodes
  'light' with a catalog fallback (no global/env lookup).
- AdminSettingsService: buildPageData, sanitization, audit snapshot, apply
  step and cache payload are all stripped of the three keys. Dead helper
  applyAppPrimaryColor + normalizePrimaryColor removed.
- Cache: SettingCacheService HOT_PATH_KEYS drops the three keys.
- API: /settings (GET/PUT) and /settings/public (GET) no longer expose
  appearance fields; OpenAPI schemas pruned accordingly.
- Audit redaction list shortened.
- DB: db/init/init.sql seed rows removed. No migration for existing
  installs — legacy rows stay inert.
- i18n + docs: setting.app_theme, setting.app_theme_user,
  setting.app_primary_color removed from de+en locales; reference and
  explanation docs updated.
- Tests: covering tests for the removed methods pruned; ThemeResolutionTest
  rewritten for tenant-only semantics. One unrelated PHP-CS-Fixer issue in
  UserRegistrar.php cleaned up to keep QG-006 green.

Workflow: .agents/runs/SETTINGS-APPEARANCE-TENANT-ONLY/ (gitignored).
Gates: QG-001..003, QG-006, QG-008 all pass (1985 tests, 28764 assertions).
Reviews: code, security, acceptance all pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-22 22:40:15 +02:00
parent 3c6ce0cbdb
commit 149d4515de
34 changed files with 164 additions and 551 deletions

View File

@@ -25,62 +25,6 @@ use PHPUnit\Framework\TestCase;
class AdminSettingsServiceAppTest extends TestCase
{
// ---------------------------------------------------------------
// Primary color
// ---------------------------------------------------------------
public function testUpdateFromAdminPersistsValidPrimaryColor(): void
{
$appGateway = $this->createMock(SettingsAppGateway::class);
$appGateway->method('getAppLocale')->willReturn('de');
$appGateway->method('getAppTheme')->willReturn('light');
$appGateway->method('isUserThemeAllowed')->willReturn(true);
$appGateway->method('isRegistrationEnabled')->willReturn(true);
$appGateway->method('getAppPrimaryColor')->willReturn('#2FA4A4');
$appGateway->method('setAppTitle')->willReturn(true);
$appGateway->method('setAppLocale')->willReturn(true);
$appGateway->method('setAppTheme')->willReturn(true);
$appGateway->method('setUserThemeAllowed')->willReturn(true);
$appGateway->method('setRegistrationEnabled')->willReturn(true);
$appGateway->expects($this->once())
->method('setAppPrimaryColor')
->with('#2FA4A4')
->willReturn(true);
$service = $this->newService(settingsAppGateway: $appGateway);
$result = $service->updateFromAdmin($this->validPostData([
'app_primary_color' => '#2FA4A4',
]));
$this->assertSame([], $result['errors'] ?? []);
}
public function testUpdateFromAdminReturnsErrorForInvalidPrimaryColor(): void
{
$appGateway = $this->createMock(SettingsAppGateway::class);
$appGateway->method('getAppLocale')->willReturn('de');
$appGateway->method('getAppTheme')->willReturn('light');
$appGateway->method('isUserThemeAllowed')->willReturn(true);
$appGateway->method('isRegistrationEnabled')->willReturn(true);
$appGateway->method('getAppPrimaryColor')->willReturn('#2FA4A4');
$appGateway->method('setAppTitle')->willReturn(true);
$appGateway->method('setAppLocale')->willReturn(true);
$appGateway->method('setAppTheme')->willReturn(true);
$appGateway->method('setUserThemeAllowed')->willReturn(true);
$appGateway->method('setRegistrationEnabled')->willReturn(true);
$appGateway->expects($this->once())
->method('setAppPrimaryColor')
->with('not-a-color')
->willReturn(false);
$service = $this->newService(settingsAppGateway: $appGateway);
$result = $service->updateFromAdmin($this->validPostData([
'app_primary_color' => 'not-a-color',
]));
$this->assertContains('app_primary_invalid', $this->extractErrorKeys($result));
}
// ---------------------------------------------------------------
// buildPageData: sorted tenants/roles/departments
// ---------------------------------------------------------------
@@ -165,10 +109,7 @@ class AdminSettingsServiceAppTest extends TestCase
'default_department_id',
'app_title',
'app_locale',
'app_theme',
'app_theme_user',
'app_registration',
'app_primary_color',
'api_token_default_ttl_days',
'api_token_max_ttl_days',
'user_inactivity_deactivate_days',
@@ -248,19 +189,6 @@ class AdminSettingsServiceAppTest extends TestCase
// Helpers
// ---------------------------------------------------------------
/** @return list<string> */
private function extractErrorKeys(array $result): array
{
$errors = is_array($result['errors'] ?? null) ? $result['errors'] : [];
$errorKeys = [];
foreach ($errors as $error) {
if (is_array($error) && isset($error['key'])) {
$errorKeys[] = (string) $error['key'];
}
}
return $errorKeys;
}
/**
* @param array<string, mixed> $overrides
* @return array<string, mixed>
@@ -273,8 +201,6 @@ class AdminSettingsServiceAppTest extends TestCase
'default_department_id' => '0',
'app_title' => 'Demo',
'app_locale' => 'de',
'app_theme' => 'light',
'app_theme_user' => '1',
'app_registration' => '1',
'api_token_default_ttl_days' => '90',
'api_token_max_ttl_days' => '365',
@@ -288,7 +214,6 @@ class AdminSettingsServiceAppTest extends TestCase
'frontend_telemetry_enabled' => '1',
'frontend_telemetry_sample_rate' => '0.2',
'frontend_telemetry_allowed_events' => ['warn_once'],
'app_primary_color' => '#2FA4A4',
'smtp_host' => '',
'smtp_port' => '',
'smtp_user' => '',
@@ -324,16 +249,10 @@ class AdminSettingsServiceAppTest extends TestCase
$settingsAppGateway = $settingsAppGateway ?? $this->createConfiguredMock(SettingsAppGateway::class, [
'getAppLocale' => 'de',
'getAppTheme' => 'light',
'isUserThemeAllowed' => true,
'isRegistrationEnabled' => true,
'getAppPrimaryColor' => '#2FA4A4',
'setAppTitle' => true,
'setAppLocale' => true,
'setAppTheme' => true,
'setUserThemeAllowed' => true,
'setRegistrationEnabled' => true,
'setAppPrimaryColor' => true,
]);
$settingsApiPolicyGateway = $this->createConfiguredMock(SettingsApiPolicyGateway::class, [