From 6dcb2910b5a854d7f587d2bf1aba4c40ebce71c1 Mon Sep 17 00:00:00 2001 From: Kostiantyn Miakshyn Date: Tue, 7 Jan 2025 16:48:33 +0100 Subject: [PATCH] fix: Apply enforce theme config for anonymous users as well Signed-off-by: Kostiantyn Miakshyn --- apps/theming/lib/Service/ThemesService.php | 5 ++++- core/templates/layout.public.php | 4 +++- lib/private/TemplateLayout.php | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/theming/lib/Service/ThemesService.php b/apps/theming/lib/Service/ThemesService.php index 433555c980c74..39a8eeff41052 100644 --- a/apps/theming/lib/Service/ThemesService.php +++ b/apps/theming/lib/Service/ThemesService.php @@ -154,12 +154,15 @@ public function isEnabled(ITheme $theme): bool { * @return string[] */ public function getEnabledThemes(): array { + $enforcedTheme = $this->config->getSystemValueString('enforce_theme', ''); $user = $this->userSession->getUser(); if ($user === null) { + if ($enforcedTheme !== '') { + return [$enforcedTheme]; + } return []; } - $enforcedTheme = $this->config->getSystemValueString('enforce_theme', ''); $enabledThemes = json_decode($this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', '["default"]')); if ($enforcedTheme !== '') { return array_merge([$enforcedTheme], $enabledThemes); diff --git a/core/templates/layout.public.php b/core/templates/layout.public.php index bd46ee4f7fc7e..3f0cc3e5d99dd 100644 --- a/core/templates/layout.public.php +++ b/core/templates/layout.public.php @@ -36,7 +36,9 @@ - + data-themes="">
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 2bc9ff5a2af74..e4978916ec365 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -158,6 +158,14 @@ public function __construct($renderAs, $appId = '') { $this->assign('appid', $appId); $this->assign('bodyid', 'body-public'); + // Set body data-theme + $this->assign('enabledThemes', []); + if ($this->appManager->isEnabledForUser('theming') && class_exists('\OCA\Theming\Service\ThemesService')) { + /** @var \OCA\Theming\Service\ThemesService $themesService */ + $themesService = \OC::$server->get(\OCA\Theming\Service\ThemesService::class); + $this->assign('enabledThemes', $themesService->getEnabledThemes()); + } + // Set logo link target $logoUrl = $this->config->getSystemValueString('logo_url', ''); $this->assign('logoUrl', $logoUrl);