StyleSheet: Do not rely on config to trigger auth

fixes #5385

(cherry picked from commit 5d71d09e548e048e8b275afc203cfa1bc2707ba8)
This commit is contained in:
Johannes Meyer 2025-07-08 15:01:45 +02:00
parent 6d18f00ed0
commit d7ec19d829

View File

@ -139,6 +139,7 @@ class StyleSheet
$this->lessCompiler->addLessFile($this->pubPath . '/' . $lessFile);
}
$auth = Auth::getInstance();
$mm = $this->app->getModuleManager();
foreach ($mm->getLoadedModules() as $moduleName => $module) {
@ -157,7 +158,6 @@ class StyleSheet
}
if (! (bool) $themingConfig->get('disabled', false)) {
$auth = Auth::getInstance();
if ($auth->isAuthenticated()) {
$userTheme = $auth->getUser()->getPreferences()->getValue('icingaweb', 'theme');
if ($userTheme !== null) {
@ -174,7 +174,7 @@ class StyleSheet
Logger::warning(sprintf(
'Theme "%s" set by user "%s" has not been found.',
$theme,
($user = Auth::getInstance()->getUser()) !== null ? $user->getUsername() : 'anonymous'
$auth->isAuthenticated() ? $auth->getUser()->getUsername() : 'anonymous'
));
}
}
@ -184,10 +184,10 @@ class StyleSheet
}
$mode = 'none';
if ($user = Auth::getInstance()->getUser()) {
if ($auth->isAuthenticated()) {
$file = $themePath !== null ? @file_get_contents($themePath) : false;
if (! $file || strpos($file, self::LIGHT_MODE_IDENTIFIER) !== false) {
$mode = $user->getPreferences()->getValue('icingaweb', 'theme_mode', self::DEFAULT_MODE);
$mode = $auth->getUser()->getPreferences()->getValue('icingaweb', 'theme_mode', self::DEFAULT_MODE);
}
}