Skip to content

Commit 6b0d3b6

Browse files
Kocsusnux
authored andcommitted
fix: Apply enforce theme config for anonymous users as well
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent 2152650 commit 6b0d3b6

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

apps/theming/lib/Service/ThemesService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,15 @@ public function isEnabled(ITheme $theme): bool {
170170
* @return string[]
171171
*/
172172
public function getEnabledThemes(): array {
173+
$enforcedTheme = $this->config->getSystemValueString('enforce_theme', '');
173174
$user = $this->userSession->getUser();
174175
if ($user === null) {
176+
if ($enforcedTheme !== '') {
177+
return [$enforcedTheme];
178+
}
175179
return [];
176180
}
177181

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

core/templates/layout.public.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
<?php emit_script_loading_tags($_); ?>
2727
<?php print_unescaped($_['headers']); ?>
2828
</head>
29-
<body id="<?php p($_['bodyid']);?>">
30-
<?php include('layout.noscript.warning.php'); ?>
31-
<?php foreach ($_['initialStates'] as $app => $initialState) { ?>
32-
<input type="hidden" id="initial-state-<?php p($app); ?>" value="<?php p(base64_encode($initialState)); ?>">
33-
<?php }?>
29+
<body id="<?php p($_['bodyid']);?>" <?php foreach ($_['enabledThemes'] as $themeId) {
30+
p("data-theme-$themeId ");
31+
}?> data-themes="<?php p(join(',', $_['enabledThemes'])) ?>">
32+
<?php include('layout.noscript.warning.php'); ?>
33+
<?php foreach ($_['initialStates'] as $app => $initialState) { ?>
34+
<input type="hidden" id="initial-state-<?php p($app); ?>" value="<?php p(base64_encode($initialState)); ?>">
35+
<?php }?>
3436
<div id="skip-actions">
3537
<?php if ($_['id-app-content'] !== null) { ?><a href="<?php p($_['id-app-content']); ?>" class="button primary skip-navigation skip-content"><?php p($l->t('Skip to main content')); ?></a><?php } ?>
3638
<?php if ($_['id-app-navigation'] !== null) { ?><a href="<?php p($_['id-app-navigation']); ?>" class="button primary skip-navigation"><?php p($l->t('Skip to navigation of app')); ?></a><?php } ?>

lib/private/TemplateLayout.php

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

193+
// Set body data-theme
194+
$this->assign('enabledThemes', []);
195+
if ($this->appManager->isEnabledForUser('theming') && class_exists('\OCA\Theming\Service\ThemesService')) {
196+
/** @var \OCA\Theming\Service\ThemesService $themesService */
197+
$themesService = \OC::$server->get(\OCA\Theming\Service\ThemesService::class);
198+
$this->assign('enabledThemes', $themesService->getEnabledThemes());
199+
}
200+
193201
// Set logo link target
194202
$logoUrl = $this->config->getSystemValueString('logo_url', '');
195203
$this->assign('logoUrl', $logoUrl);

0 commit comments

Comments
 (0)