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

@@ -55,10 +55,7 @@ class AdminSettingsService
'default_department_id' => $this->settingsDefaultsGateway->getDefaultDepartmentId(),
'app_title' => $this->settingsMetadataGateway->getValue(SettingKeys::APP_TITLE_KEY),
'app_locale' => $this->settingsMetadataGateway->getValue(SettingKeys::APP_LOCALE_KEY),
'app_theme' => $this->settingsMetadataGateway->getValue(SettingKeys::APP_THEME_KEY),
'app_theme_user' => $this->settingsAppGateway->isUserThemeAllowed(),
'app_registration' => $this->settingsAppGateway->isRegistrationEnabled(),
'app_primary_color' => $this->settingsMetadataGateway->getValue(SettingKeys::APP_PRIMARY_COLOR_KEY),
'api_token_default_ttl_days' => $this->settingsApiPolicyGateway->getApiTokenDefaultTtlDays(),
'api_token_max_ttl_days' => $this->settingsApiPolicyGateway->getApiTokenMaxTtlDays(),
'user_inactivity_deactivate_days' => $this->settingsUserLifecycleGateway->getUserInactivityDeactivateDays(),
@@ -88,10 +85,7 @@ class AdminSettingsService
'default_department' => $this->settingsMetadataGateway->get(SettingKeys::DEFAULT_DEPARTMENT_KEY),
'app_title' => $this->settingsMetadataGateway->get(SettingKeys::APP_TITLE_KEY),
'app_locale' => $this->settingsMetadataGateway->get(SettingKeys::APP_LOCALE_KEY),
'app_theme' => $this->settingsMetadataGateway->get(SettingKeys::APP_THEME_KEY),
'app_theme_user' => $this->settingsMetadataGateway->get(SettingKeys::APP_THEME_USER_KEY),
'app_registration' => $this->settingsMetadataGateway->get(SettingKeys::APP_REGISTRATION_KEY),
'app_primary_color' => $this->settingsMetadataGateway->get(SettingKeys::APP_PRIMARY_COLOR_KEY),
'api_token_default_ttl_days' => $this->settingsMetadataGateway->get(SettingKeys::API_TOKEN_DEFAULT_TTL_DAYS_KEY),
'api_token_max_ttl_days' => $this->settingsMetadataGateway->get(SettingKeys::API_TOKEN_MAX_TTL_DAYS_KEY),
'user_inactivity_deactivate_days' => $this->settingsMetadataGateway->get(SettingKeys::USER_INACTIVITY_DEACTIVATE_DAYS_KEY),
@@ -132,7 +126,6 @@ class AdminSettingsService
array_push($errors, ...$this->applyApiAndLifecycleSettings($input));
array_push($errors, ...$this->applySessionAndLoginSettings($input));
array_push($errors, ...$this->applyAuditAndTelemetrySettings($input));
array_push($errors, ...$this->applyAppPrimaryColor($input));
$this->applySmtpSettings($input);
array_push($errors, ...$this->applyMicrosoftSettings($input));
$this->updateSettingsCache($input);
@@ -159,10 +152,7 @@ class AdminSettingsService
'default_department_id' => (int) ($post['default_department_id'] ?? 0),
'app_title' => trim((string) ($post['app_title'] ?? '')),
'app_locale' => trim((string) ($post['app_locale'] ?? '')),
'app_theme' => trim((string) ($post['app_theme'] ?? '')),
'app_theme_user' => isset($post['app_theme_user']),
'app_registration' => isset($post['app_registration']),
'app_primary_color' => $this->normalizePrimaryColor($post['app_primary_color'] ?? ''),
'api_token_default_ttl_days' => (int) ($post['api_token_default_ttl_days'] ?? 0),
'api_token_max_ttl_days' => (int) ($post['api_token_max_ttl_days'] ?? 0),
'api_cors_allowed_origins' => $this->normalizeScalarText($post['api_cors_allowed_origins'] ?? ''),
@@ -203,10 +193,7 @@ class AdminSettingsService
'default_role_id' => $this->settingsDefaultsGateway->getDefaultRoleId(),
'default_department_id' => $this->settingsDefaultsGateway->getDefaultDepartmentId(),
'app_locale' => $this->settingsAppGateway->getAppLocale(),
'app_theme' => $this->settingsAppGateway->getAppTheme(),
'app_theme_user' => $this->settingsAppGateway->isUserThemeAllowed(),
'app_registration' => $this->settingsAppGateway->isRegistrationEnabled(),
'app_primary_color' => $this->settingsAppGateway->getAppPrimaryColor(),
'api_token_default_ttl_days' => $this->settingsApiPolicyGateway->getApiTokenDefaultTtlDays(),
'api_token_max_ttl_days' => $this->settingsApiPolicyGateway->getApiTokenMaxTtlDays(),
'user_inactivity_deactivate_days' => $this->settingsUserLifecycleGateway->getUserInactivityDeactivateDays(),
@@ -230,8 +217,6 @@ class AdminSettingsService
$this->settingsDefaultsGateway->setDefaultDepartmentId($input['default_department_id'] > 0 ? $input['default_department_id'] : null);
$this->settingsAppGateway->setAppTitle($input['app_title']);
$this->settingsAppGateway->setAppLocale($input['app_locale']);
$this->settingsAppGateway->setAppTheme($input['app_theme']);
$this->settingsAppGateway->setUserThemeAllowed($input['app_theme_user']);
$this->settingsAppGateway->setRegistrationEnabled($input['app_registration']);
}
@@ -316,16 +301,6 @@ class AdminSettingsService
return $errors;
}
/** @return list<array{message: string, key: string}> */
private function applyAppPrimaryColor(array &$input): array
{
if (!$this->settingsAppGateway->setAppPrimaryColor($input['app_primary_color'])) {
$input['app_primary_color'] = '';
return [['message' => 'Primary color is invalid', 'key' => 'app_primary_invalid']];
}
return [];
}
private function applySmtpSettings(array $input): void
{
$this->settingsSmtpGateway->setSmtpHost($input['smtp_host']);
@@ -364,10 +339,7 @@ class AdminSettingsService
$this->settingCacheService->update([
'app_title' => $input['app_title'] !== '' ? $input['app_title'] : null,
'app_locale' => $input['app_locale'] !== '' ? $input['app_locale'] : null,
'app_theme' => $input['app_theme'] !== '' ? $input['app_theme'] : null,
'app_theme_user' => $input['app_theme_user'] ? '1' : '0',
'app_registration' => $input['app_registration'] ? '1' : '0',
'app_primary_color' => $input['app_primary_color'] !== '' ? $input['app_primary_color'] : null,
'api_token_default_ttl_days' => (string) $this->settingsApiPolicyGateway->getApiTokenDefaultTtlDays(),
'api_token_max_ttl_days' => (string) $this->settingsApiPolicyGateway->getApiTokenMaxTtlDays(),
'api_cors_allowed_origins' => $this->settingsMetadataGateway->getValue(SettingKeys::API_CORS_ALLOWED_ORIGINS_KEY),
@@ -406,13 +378,4 @@ class AdminSettingsService
return trim((string) $value);
}
private function normalizePrimaryColor(mixed $value): string
{
$color = $this->normalizeScalarText($value);
if (in_array(strtolower($color), ['null', 'undefined'], true)) {
return '';
}
return $color;
}
}