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

@@ -7,6 +7,14 @@ use MintyPHP\Service\Settings\SettingCacheService;
use MintyPHP\Service\Settings\ThemeConfigGateway;
use PHPUnit\Framework\TestCase;
/**
* Appearance resolution is tenant-scoped:
*
* - appDefaultTheme() uses tenant.default_theme, else hardcoded 'light'.
* - allowUserTheme() uses tenant.allow_user_theme, else defaults to true.
* - Global app settings no longer participate — this class verifies the
* fallback chain and confirms global settings are inert.
*/
class ThemeResolutionTest extends TestCase
{
use AppContainerIsolationTrait;
@@ -36,21 +44,22 @@ class ThemeResolutionTest extends TestCase
// -- appDefaultTheme priority chain --
public function testDefaultThemeFallsBackToLight(): void
public function testDefaultThemeFallsBackToLightWithoutTenant(): void
{
$this->assertSame('light', appDefaultTheme());
}
public function testDefaultThemeReadsAppSetting(): void
public function testDefaultThemeIgnoresGlobalAppSetting(): void
{
// A stale global setting in the cache must no longer influence the
// resolution — appearance is tenant-scoped, no global fallback.
$this->setAppSettings(['app_theme' => 'dark']);
$this->assertSame('dark', appDefaultTheme());
$this->assertSame('light', appDefaultTheme());
}
public function testDefaultThemeTenantOverridesAppSetting(): void
public function testDefaultThemeUsesTenantValue(): void
{
$this->setAppSettings(['app_theme' => 'light']);
$_SESSION['current_tenant'] = ['default_theme' => 'dark'];
$this->assertSame('dark', appDefaultTheme());
@@ -65,10 +74,9 @@ class ThemeResolutionTest extends TestCase
public function testDefaultThemeIgnoresEmptyTenantTheme(): void
{
$this->setAppSettings(['app_theme' => 'dark']);
$_SESSION['current_tenant'] = ['default_theme' => ''];
$this->assertSame('dark', appDefaultTheme());
$this->assertSame('light', appDefaultTheme());
}
// -- currentTheme with user override --
@@ -107,7 +115,7 @@ class ThemeResolutionTest extends TestCase
// -- allowUserTheme feature flag --
public function testAllowUserThemeDefaultsToTrue(): void
public function testAllowUserThemeDefaultsToTrueWithoutTenant(): void
{
$this->assertTrue(allowUserTheme());
}
@@ -126,19 +134,33 @@ class ThemeResolutionTest extends TestCase
$this->assertFalse(allowUserTheme());
}
public function testAllowUserThemeTenantOverridesAppSetting(): void
{
$this->setAppSettings(['app_theme_user' => '1']);
$_SESSION['current_tenant'] = ['allow_user_theme' => '0'];
$this->assertFalse(allowUserTheme());
}
public function testAllowUserThemeFallsBackToAppSettingWhenTenantNull(): void
public function testAllowUserThemeIgnoresGlobalAppSetting(): void
{
// Legacy global setting must not override the tenant-null default.
$this->setAppSettings(['app_theme_user' => '0']);
$this->assertFalse(allowUserTheme());
$this->assertTrue(allowUserTheme());
}
public function testAppPrimaryColorIgnoresGlobalAppSetting(): void
{
$this->setAppSettings(['app_primary_color' => '#112233']);
$this->assertNull(appPrimaryColor());
}
public function testAppPrimaryColorReadsTenantValue(): void
{
$_SESSION['current_tenant'] = ['primary_color' => '#abcdef'];
$this->assertSame('#abcdef', appPrimaryColor());
}
public function testAppPrimaryColorRejectsInvalidTenantValue(): void
{
$_SESSION['current_tenant'] = ['primary_color' => 'not-a-color'];
$this->assertNull(appPrimaryColor());
}
// -- Tenant switch scenarios --