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:
@@ -313,8 +313,6 @@ class AdminSettingsServiceApiLifecycleTest 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',
|
||||
@@ -328,7 +326,6 @@ class AdminSettingsServiceApiLifecycleTest 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' => '',
|
||||
@@ -359,16 +356,10 @@ class AdminSettingsServiceApiLifecycleTest extends TestCase
|
||||
|
||||
$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 = $settingsApiPolicyGateway ?? $this->createConfiguredMock(SettingsApiPolicyGateway::class, [
|
||||
|
||||
@@ -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, [
|
||||
|
||||
@@ -396,8 +396,6 @@ class AdminSettingsServiceSecurityTest 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',
|
||||
@@ -411,7 +409,6 @@ class AdminSettingsServiceSecurityTest 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' => '',
|
||||
@@ -443,16 +440,10 @@ class AdminSettingsServiceSecurityTest extends TestCase
|
||||
|
||||
$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, [
|
||||
|
||||
@@ -193,8 +193,6 @@ class AdminSettingsServiceSessionPolicyTest 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',
|
||||
@@ -208,7 +206,6 @@ class AdminSettingsServiceSessionPolicyTest 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' => '',
|
||||
@@ -240,16 +237,10 @@ class AdminSettingsServiceSessionPolicyTest extends TestCase
|
||||
|
||||
$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, [
|
||||
|
||||
@@ -45,16 +45,13 @@ class SettingCacheServiceTest extends TestCase
|
||||
$file = $this->tempFilePath();
|
||||
|
||||
$metadataGateway = $this->createMock(SettingsMetadataGateway::class);
|
||||
$metadataGateway->expects($this->exactly(6))
|
||||
$metadataGateway->expects($this->exactly(3))
|
||||
->method('getValue')
|
||||
->willReturnCallback(static function (string $key): ?string {
|
||||
return match ($key) {
|
||||
SettingKeys::APP_TITLE_KEY => 'Demo App',
|
||||
SettingKeys::APP_LOCALE_KEY => 'de',
|
||||
SettingKeys::APP_THEME_KEY => 'dark',
|
||||
SettingKeys::APP_THEME_USER_KEY => '1',
|
||||
SettingKeys::APP_REGISTRATION_KEY => '0',
|
||||
SettingKeys::APP_PRIMARY_COLOR_KEY => '#112233',
|
||||
default => null,
|
||||
};
|
||||
});
|
||||
@@ -66,7 +63,7 @@ class SettingCacheServiceTest extends TestCase
|
||||
/** @var array<string, string> $cache */
|
||||
$cache = include $file;
|
||||
$this->assertSame('de', $cache[SettingKeys::APP_LOCALE_KEY] ?? null);
|
||||
$this->assertSame('#112233', $cache[SettingKeys::APP_PRIMARY_COLOR_KEY] ?? null);
|
||||
$this->assertSame('0', $cache[SettingKeys::APP_REGISTRATION_KEY] ?? null);
|
||||
}
|
||||
|
||||
private function tempFilePath(): string
|
||||
|
||||
@@ -10,19 +10,12 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SettingsAppGatewayTest extends TestCase
|
||||
{
|
||||
private function createGateway(SettingRepositoryInterface $settings, ?ThemeConfigGateway $themeConfig = null): SettingsAppGateway
|
||||
{
|
||||
$themeConfig ??= $this->createDefaultThemeConfig();
|
||||
|
||||
return new SettingsAppGateway(new SettingsMetadataGateway($settings), $themeConfig);
|
||||
}
|
||||
|
||||
private function createDefaultThemeConfig(): ThemeConfigGateway
|
||||
private function createGateway(SettingRepositoryInterface $settings): SettingsAppGateway
|
||||
{
|
||||
$themeConfig = $this->createMock(ThemeConfigGateway::class);
|
||||
$themeConfig->method('all')->willReturn(['light' => 'Light', 'dark' => 'Dark']);
|
||||
|
||||
return $themeConfig;
|
||||
return new SettingsAppGateway(new SettingsMetadataGateway($settings), $themeConfig);
|
||||
}
|
||||
|
||||
public function testGetAppTitleReturnsNullWhenEmpty(): void
|
||||
@@ -69,38 +62,4 @@ class SettingsAppGatewayTest extends TestCase
|
||||
$gateway = $this->createGateway($settings);
|
||||
$this->assertFalse($gateway->isRegistrationEnabled());
|
||||
}
|
||||
|
||||
public function testGetAppPrimaryColorRejectsInvalidFormat(): void
|
||||
{
|
||||
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||||
$settings->expects($this->any())->method('getValue')->with('app_primary_color')->willReturn('not-a-color');
|
||||
|
||||
$gateway = $this->createGateway($settings);
|
||||
$this->assertNull($gateway->getAppPrimaryColor());
|
||||
}
|
||||
|
||||
public function testGetAppPrimaryColorReturnsValidHex(): void
|
||||
{
|
||||
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||||
$settings->expects($this->any())->method('getValue')->with('app_primary_color')->willReturn('#ff5500');
|
||||
|
||||
$gateway = $this->createGateway($settings);
|
||||
$this->assertSame('#ff5500', $gateway->getAppPrimaryColor());
|
||||
}
|
||||
|
||||
public function testIsAllowedThemeReturnsTrueForKnownTheme(): void
|
||||
{
|
||||
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||||
|
||||
$gateway = $this->createGateway($settings);
|
||||
$this->assertTrue($gateway->isAllowedTheme('dark'));
|
||||
}
|
||||
|
||||
public function testIsAllowedThemeReturnsFalseForUnknownTheme(): void
|
||||
{
|
||||
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||||
|
||||
$gateway = $this->createGateway($settings);
|
||||
$this->assertFalse($gateway->isAllowedTheme('neon'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,52 +25,17 @@ final class SettingsGatewayNormalizationTest extends TestCase
|
||||
self::assertTrue($gateway->setAppLocale(' '));
|
||||
}
|
||||
|
||||
public function testAppThemeStoresNullForUnknownTheme(): void
|
||||
{
|
||||
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||||
$settings->expects($this->once())
|
||||
->method('set')
|
||||
->with('app_theme', null, 'setting.app_theme')
|
||||
->willReturn(true);
|
||||
|
||||
$gateway = $this->newAppGateway($settings);
|
||||
self::assertTrue($gateway->setAppTheme('unknown'));
|
||||
}
|
||||
|
||||
public function testAppBooleanFlagsUseExpectedDefaults(): void
|
||||
public function testAppRegistrationDefaultIsTrueWhenUnset(): void
|
||||
{
|
||||
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||||
$settings->method('getValue')->willReturnMap([
|
||||
['app_theme_user', null],
|
||||
['app_registration', null],
|
||||
]);
|
||||
|
||||
$gateway = $this->newAppGateway($settings);
|
||||
self::assertTrue($gateway->isUserThemeAllowed());
|
||||
self::assertTrue($gateway->isRegistrationEnabled());
|
||||
}
|
||||
|
||||
public function testAppPrimaryColorNormalizesHexWithoutHash(): void
|
||||
{
|
||||
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||||
$settings->expects($this->once())
|
||||
->method('set')
|
||||
->with('app_primary_color', '#abc', 'setting.app_primary_color')
|
||||
->willReturn(true);
|
||||
|
||||
$gateway = $this->newAppGateway($settings);
|
||||
self::assertTrue($gateway->setAppPrimaryColor('abc'));
|
||||
}
|
||||
|
||||
public function testAppPrimaryColorRejectsInvalidValue(): void
|
||||
{
|
||||
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||||
$settings->expects($this->never())->method('set');
|
||||
|
||||
$gateway = $this->newAppGateway($settings);
|
||||
self::assertFalse($gateway->setAppPrimaryColor('not-a-color'));
|
||||
}
|
||||
|
||||
public function testSystemAuditUsesFallbacksAndRejectsOutOfRangeRetention(): void
|
||||
{
|
||||
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||||
@@ -159,9 +124,9 @@ final class SettingsGatewayNormalizationTest extends TestCase
|
||||
|
||||
private function newAppGateway(SettingRepositoryInterface $settingRepository): SettingsAppGateway
|
||||
{
|
||||
$themeConfigService = $this->createMock(ThemeConfigGateway::class);
|
||||
$themeConfigService->method('all')->willReturn(['light' => 'Light', 'dark' => 'Dark']);
|
||||
$themeConfig = $this->createMock(ThemeConfigGateway::class);
|
||||
$themeConfig->method('all')->willReturn(['light' => 'Light', 'dark' => 'Dark']);
|
||||
|
||||
return new SettingsAppGateway(new SettingsMetadataGateway($settingRepository), $themeConfigService);
|
||||
return new SettingsAppGateway(new SettingsMetadataGateway($settingRepository), $themeConfig);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user