Skip to content

Commit 30d12a0

Browse files
committed
fix: Apply enforce theme config for anonymous users as well
Signed-off-by: Kostiantyn Miakshyn <[email protected]>
1 parent d1507f6 commit 30d12a0

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

apps/theming/lib/Service/ThemesService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,15 @@ public function isEnabled(ITheme $theme): bool {
153153
* @return string[]
154154
*/
155155
public function getEnabledThemes(): array {
156+
$enforcedTheme = $this->config->getSystemValueString('enforce_theme', '');
156157
$user = $this->userSession->getUser();
157158
if ($user === null) {
159+
if ($enforcedTheme !== '') {
160+
return [$enforcedTheme];
161+
}
158162
return [];
159163
}
160164

161-
$enforcedTheme = $this->config->getSystemValueString('enforce_theme', '');
162165
$enabledThemes = json_decode($this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', '["default"]'));
163166
if ($enforcedTheme !== '') {
164167
return array_merge([$enforcedTheme], $enabledThemes);

core/templates/layout.public.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
<?php emit_script_loading_tags($_); ?>
3636
<?php print_unescaped($_['headers']); ?>
3737
</head>
38-
<body id="<?php p($_['bodyid']);?>">
38+
<body id="<?php p($_['bodyid']);?>" <?php foreach ($_['enabledThemes'] as $themeId) {
39+
p("data-theme-$themeId ");
40+
}?> data-themes="<?php p(join(',', $_['enabledThemes'])) ?>">
3941
<?php include('layout.noscript.warning.php'); ?>
4042
<?php include('layout.initial-state.php'); ?>
4143
<div id="skip-actions">

lib/private/TemplateLayout.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ public function __construct($renderAs, $appId = '') {
158158
$this->assign('appid', $appId);
159159
$this->assign('bodyid', 'body-public');
160160

161+
// Set body data-theme
162+
$this->assign('enabledThemes', []);
163+
if ($this->appManager->isEnabledForUser('theming') && class_exists('\OCA\Theming\Service\ThemesService')) {
164+
/** @var \OCA\Theming\Service\ThemesService $themesService */
165+
$themesService = \OC::$server->get(\OCA\Theming\Service\ThemesService::class);
166+
$this->assign('enabledThemes', $themesService->getEnabledThemes());
167+
}
168+
161169
// Set logo link target
162170
$logoUrl = $this->config->getSystemValueString('logo_url', '');
163171
$this->assign('logoUrl', $logoUrl);

0 commit comments

Comments
 (0)