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:
@@ -11,6 +11,7 @@ use MintyPHP\Repository\User\UserReadRepository;
|
||||
use MintyPHP\Repository\User\UserWriteRepository;
|
||||
use MintyPHP\Service\Auth\TenantSsoService;
|
||||
use MintyPHP\Service\Branding\BrandingLogoService;
|
||||
use MintyPHP\Service\Tenant\TenantScopeService;
|
||||
use MintyPHP\Service\User\UserAccessPdfService;
|
||||
use MintyPHP\Service\User\UserAccessTemplateService;
|
||||
use MintyPHP\Service\User\UserAccountService;
|
||||
@@ -26,7 +27,6 @@ use MintyPHP\Service\User\UserProfileViewService;
|
||||
use MintyPHP\Service\User\UserRepositoryFactory;
|
||||
use MintyPHP\Service\User\UserServicesFactory;
|
||||
use MintyPHP\Service\User\UserTenantContextService;
|
||||
use MintyPHP\Service\Tenant\TenantScopeService;
|
||||
|
||||
final class UserRegistrar implements ContainerRegistrar
|
||||
{
|
||||
|
||||
@@ -44,11 +44,6 @@ class AuthSettingsGateway
|
||||
return $this->settingsApiPolicyGateway->getApiTokenDefaultTtlDays();
|
||||
}
|
||||
|
||||
public function getAppTheme(): string
|
||||
{
|
||||
return (string) $this->settingsAppGateway->getAppTheme();
|
||||
}
|
||||
|
||||
public function defaultTheme(): string
|
||||
{
|
||||
return $this->settingsAppGateway->resolveDefaultTheme();
|
||||
|
||||
@@ -101,7 +101,7 @@ class SsoUserLinkService
|
||||
'password' => $this->randomPassword(),
|
||||
'locale' => $this->normalizeLocale((string) ($claims['preferred_language'] ?? '')),
|
||||
'totp_secret' => '',
|
||||
'theme' => $this->resolveInitialTheme($this->settingsGateway->getAppTheme()),
|
||||
'theme' => $this->resolveInitialTheme(null),
|
||||
'primary_tenant_id' => $tenantId,
|
||||
'current_tenant_id' => $tenantId,
|
||||
'active' => 1,
|
||||
@@ -293,7 +293,7 @@ class SsoUserLinkService
|
||||
'password' => $this->randomPassword(),
|
||||
'locale' => null,
|
||||
'totp_secret' => '',
|
||||
'theme' => $this->resolveInitialTheme($this->settingsGateway->getAppTheme()),
|
||||
'theme' => $this->resolveInitialTheme(null),
|
||||
'primary_tenant_id' => $tenantId,
|
||||
'current_tenant_id' => $tenantId,
|
||||
'active' => 1,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ class SettingCacheService
|
||||
private const HOT_PATH_KEYS = [
|
||||
SettingKeys::APP_TITLE_KEY,
|
||||
SettingKeys::APP_LOCALE_KEY,
|
||||
SettingKeys::APP_THEME_KEY,
|
||||
SettingKeys::APP_THEME_USER_KEY,
|
||||
SettingKeys::APP_REGISTRATION_KEY,
|
||||
SettingKeys::APP_PRIMARY_COLOR_KEY,
|
||||
];
|
||||
|
||||
private ?array $settings = null;
|
||||
|
||||
@@ -9,10 +9,7 @@ final class SettingKeys
|
||||
public const DEFAULT_DEPARTMENT_KEY = 'default_department_id';
|
||||
public const APP_TITLE_KEY = 'app_title';
|
||||
public const APP_LOCALE_KEY = 'app_locale';
|
||||
public const APP_THEME_KEY = 'app_theme';
|
||||
public const APP_THEME_USER_KEY = 'app_theme_user';
|
||||
public const APP_REGISTRATION_KEY = 'app_registration';
|
||||
public const APP_PRIMARY_COLOR_KEY = 'app_primary_color';
|
||||
public const API_TOKEN_DEFAULT_TTL_DAYS_KEY = 'api_token_default_ttl_days';
|
||||
public const API_TOKEN_MAX_TTL_DAYS_KEY = 'api_token_max_ttl_days';
|
||||
public const API_CORS_ALLOWED_ORIGINS_KEY = 'api_cors_allowed_origins';
|
||||
|
||||
@@ -4,6 +4,19 @@ namespace MintyPHP\Service\Settings;
|
||||
|
||||
use MintyPHP\I18n;
|
||||
|
||||
/**
|
||||
* App-wide (global) settings gateway.
|
||||
*
|
||||
* Appearance SETTINGS (theme, user-theme toggle, primary color) are NOT
|
||||
* managed globally — they live on the tenant (tenants.primary_color,
|
||||
* default_theme, allow_user_theme) and are resolved by branding helpers.
|
||||
*
|
||||
* The theme CATALOG utilities (listThemes, isAllowedTheme, normalizeTheme,
|
||||
* resolveDefaultTheme) stay because consumers across Tenant / Auth / User
|
||||
* flows need to validate a theme value and resolve a safe default. There is
|
||||
* no global setting lookup in these helpers anymore — the default is a
|
||||
* hardcoded 'light' falling back to the first available catalog entry.
|
||||
*/
|
||||
class SettingsAppGateway
|
||||
{
|
||||
public function __construct(
|
||||
@@ -53,87 +66,6 @@ class SettingsAppGateway
|
||||
return $this->settingsMetadataGateway->set(SettingKeys::APP_LOCALE_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public function getAppTheme(): ?string
|
||||
{
|
||||
$value = $this->settingsMetadataGateway->getValue(SettingKeys::APP_THEME_KEY);
|
||||
$value = $value !== null ? strtolower(trim($value)) : '';
|
||||
if (!$this->isAllowedTheme($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function setAppTheme(?string $theme, ?string $description = null): bool
|
||||
{
|
||||
$value = $theme !== null ? strtolower(trim($theme)) : '';
|
||||
if ($value === '' || !$this->isAllowedTheme($value)) {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
$desc = $description ?? 'setting.app_theme';
|
||||
return $this->settingsMetadataGateway->set(SettingKeys::APP_THEME_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function listThemes(): array
|
||||
{
|
||||
return $this->themeConfigService->all();
|
||||
}
|
||||
|
||||
public function isAllowedTheme(?string $theme): bool
|
||||
{
|
||||
$value = strtolower(trim((string) $theme));
|
||||
return $value !== '' && in_array($value, $this->allowedThemes(), true);
|
||||
}
|
||||
|
||||
public function resolveDefaultTheme(): string
|
||||
{
|
||||
$settingTheme = $this->getAppTheme();
|
||||
if ($settingTheme !== null) {
|
||||
return $settingTheme;
|
||||
}
|
||||
|
||||
$envTheme = strtolower(trim((string) (getenv('APP_THEME') ?: '')));
|
||||
if ($this->isAllowedTheme($envTheme)) {
|
||||
return $envTheme;
|
||||
}
|
||||
|
||||
$allowedThemes = $this->allowedThemes();
|
||||
if (in_array('light', $allowedThemes, true)) {
|
||||
return 'light';
|
||||
}
|
||||
|
||||
return (string) ($allowedThemes[0] ?? 'light');
|
||||
}
|
||||
|
||||
public function normalizeTheme(?string $theme): string
|
||||
{
|
||||
$value = strtolower(trim((string) $theme));
|
||||
if ($this->isAllowedTheme($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $this->resolveDefaultTheme();
|
||||
}
|
||||
|
||||
public function isUserThemeAllowed(): bool
|
||||
{
|
||||
return settingToBool(
|
||||
$this->settingsMetadataGateway->getValue(SettingKeys::APP_THEME_USER_KEY),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public function setUserThemeAllowed(bool $allowed, ?string $description = null): bool
|
||||
{
|
||||
$value = $allowed ? '1' : '0';
|
||||
$desc = $description ?? 'setting.app_theme_user';
|
||||
return $this->settingsMetadataGateway->set(SettingKeys::APP_THEME_USER_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public function isRegistrationEnabled(): bool
|
||||
{
|
||||
return settingToBool(
|
||||
@@ -149,44 +81,46 @@ class SettingsAppGateway
|
||||
return $this->settingsMetadataGateway->set(SettingKeys::APP_REGISTRATION_KEY, $value, $desc);
|
||||
}
|
||||
|
||||
public function getAppPrimaryColor(): ?string
|
||||
/**
|
||||
* Catalog of available themes — purely code-level (config/themes.php),
|
||||
* not a global setting.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function listThemes(): array
|
||||
{
|
||||
$value = $this->settingsMetadataGateway->getValue(SettingKeys::APP_PRIMARY_COLOR_KEY);
|
||||
$value = $value !== null ? strtolower(trim($value)) : '';
|
||||
if ($value === '') {
|
||||
return null;
|
||||
}
|
||||
if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i', $value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $value;
|
||||
return $this->themeConfigService->all();
|
||||
}
|
||||
|
||||
public function setAppPrimaryColor(?string $color, ?string $description = null): bool
|
||||
public function isAllowedTheme(?string $theme): bool
|
||||
{
|
||||
$value = $color !== null ? strtolower(trim($color)) : '';
|
||||
if ($value !== '' && $value[0] !== '#') {
|
||||
if (preg_match('/^[0-9a-f]{3}$/i', $value)
|
||||
|| preg_match('/^[0-9a-f]{4}$/i', $value)
|
||||
|| preg_match('/^[0-9a-f]{6}$/i', $value)
|
||||
|| preg_match('/^[0-9a-f]{8}$/i', $value)) {
|
||||
$value = '#' . $value;
|
||||
}
|
||||
}
|
||||
if ($value === '') {
|
||||
$value = null;
|
||||
} elseif (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i', $value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$desc = $description ?? 'setting.app_primary_color';
|
||||
return $this->settingsMetadataGateway->set(SettingKeys::APP_PRIMARY_COLOR_KEY, $value, $desc);
|
||||
$value = strtolower(trim((string) $theme));
|
||||
return $value !== '' && in_array($value, $this->allowedThemes(), true);
|
||||
}
|
||||
|
||||
private function allowedThemes(): array
|
||||
/**
|
||||
* Default theme for flows that need ONE value without a tenant context
|
||||
* (user creation defaults, SSO-linked account provisioning, etc.).
|
||||
* Hardcoded to 'light' with a catalog fallback — no global setting.
|
||||
*/
|
||||
public function resolveDefaultTheme(): string
|
||||
{
|
||||
return array_keys($this->listThemes());
|
||||
$allowed = $this->allowedThemes();
|
||||
if (in_array('light', $allowed, true)) {
|
||||
return 'light';
|
||||
}
|
||||
|
||||
return (string) ($allowed[0] ?? 'light');
|
||||
}
|
||||
|
||||
public function normalizeTheme(?string $theme): string
|
||||
{
|
||||
$value = strtolower(trim((string) $theme));
|
||||
if ($this->isAllowedTheme($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $this->resolveDefaultTheme();
|
||||
}
|
||||
|
||||
public function normalizeLocale(?string $locale): string
|
||||
@@ -199,4 +133,12 @@ class SettingsAppGateway
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function allowedThemes(): array
|
||||
{
|
||||
return array_keys($this->listThemes());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,7 +613,6 @@ class UserAccountService
|
||||
return ['ok' => false, 'error' => $errors[0]];
|
||||
}
|
||||
|
||||
$defaultTheme = $this->settingsGateway->getAppTheme();
|
||||
$defaultTenantId = $this->settingsGateway->getDefaultTenantId();
|
||||
$activeChangedAt = gmdate('Y-m-d H:i:s');
|
||||
|
||||
@@ -629,7 +628,7 @@ class UserAccountService
|
||||
'password' => $password,
|
||||
'locale' => I18n::$locale,
|
||||
'totp_secret' => '',
|
||||
'theme' => $this->normalizeTheme($defaultTheme ?? 'light'),
|
||||
'theme' => $this->normalizeTheme(null),
|
||||
'primary_tenant_id' => $defaultTenantId ?: null,
|
||||
'active' => 1,
|
||||
'created_by' => null,
|
||||
|
||||
@@ -30,11 +30,6 @@ class UserSettingsGateway
|
||||
return $this->settingsDefaultsGateway->getDefaultDepartmentId();
|
||||
}
|
||||
|
||||
public function getAppTheme(): ?string
|
||||
{
|
||||
return $this->settingsAppGateway->getAppTheme();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
|
||||
@@ -265,6 +265,10 @@ function appDefaultLocale(): ?string
|
||||
|
||||
/**
|
||||
* Feature flag: allow users to choose their own theme.
|
||||
*
|
||||
* Resolved from the current tenant; defaults to true when no tenant is in
|
||||
* session or the tenant has no explicit value. Appearance is tenant-scoped —
|
||||
* there is no global setting fallback.
|
||||
*/
|
||||
function allowUserTheme(): bool
|
||||
{
|
||||
@@ -273,7 +277,7 @@ function allowUserTheme(): bool
|
||||
return settingToBool((string) $tenantValue, true);
|
||||
}
|
||||
|
||||
return settingToBool(appSetting('app_theme_user'), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,10 @@ function appThemes(): array
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve default theme from settings, then APP_THEME, then light.
|
||||
* Resolve default theme: tenant value, else hardcoded 'light'.
|
||||
*
|
||||
* Appearance is tenant-scoped — there is no global fallback layer. Pages
|
||||
* without a tenant context (login, error) land on 'light'.
|
||||
*/
|
||||
function appDefaultTheme(): string
|
||||
{
|
||||
@@ -31,13 +34,7 @@ function appDefaultTheme(): string
|
||||
if ($tenantTheme !== '' && isset($themes[$tenantTheme])) {
|
||||
return $tenantTheme;
|
||||
}
|
||||
$setting = appSetting('app_theme');
|
||||
if ($setting !== null && isset($themes[$setting])) {
|
||||
return $setting;
|
||||
}
|
||||
$envTheme = getenv('APP_THEME') ?: 'light';
|
||||
$envTheme = strtolower(trim((string) $envTheme));
|
||||
return isset($themes[$envTheme]) ? $envTheme : 'light';
|
||||
return 'light';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,28 +56,24 @@ function currentTheme(): string
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve active primary color (tenant override -> app setting).
|
||||
* Resolve active primary color from the current tenant.
|
||||
*
|
||||
* Returns null when no tenant is in session (login / error pages) or when
|
||||
* the tenant has no primary_color set. Callers must be null-safe — there is
|
||||
* no global fallback; appPrimaryCssVars() emits an empty string in that case
|
||||
* so Pico defaults apply.
|
||||
*/
|
||||
function appPrimaryColor(): ?string
|
||||
{
|
||||
// Tenant-scoped branding has precedence over global settings.
|
||||
$tenantColor = $_SESSION['current_tenant']['primary_color'] ?? null;
|
||||
if ($tenantColor !== null) {
|
||||
$tenantColor = strtolower(trim((string) $tenantColor));
|
||||
if (preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $tenantColor)) {
|
||||
return $tenantColor;
|
||||
}
|
||||
}
|
||||
|
||||
$value = appSetting('app_primary_color');
|
||||
if ($value === null) {
|
||||
if ($tenantColor === null) {
|
||||
return null;
|
||||
}
|
||||
$value = strtolower(trim($value));
|
||||
if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
|
||||
$tenantColor = strtolower(trim((string) $tenantColor));
|
||||
if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $tenantColor)) {
|
||||
return null;
|
||||
}
|
||||
return $value;
|
||||
return $tenantColor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user