Browse Source

fix: Apply enforce theme config for anonymous users as well

Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
pull/50122/head
Kostiantyn Miakshyn 10 months ago
committed by Konstantin Myakshin
parent
commit
77e8a55405
  1. 5
      apps/theming/lib/Service/ThemesService.php
  2. 4
      core/templates/layout.public.php
  3. 8
      lib/private/TemplateLayout.php

5
apps/theming/lib/Service/ThemesService.php

@ -153,12 +153,15 @@ class ThemesService {
* @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);

4
core/templates/layout.public.php

@ -35,7 +35,9 @@ p($theme->getTitle());
<?php emit_script_loading_tags($_); ?>
<?php print_unescaped($_['headers']); ?>
</head>
<body id="<?php p($_['bodyid']);?>">
<body id="<?php p($_['bodyid']);?>" <?php foreach ($_['enabledThemes'] as $themeId) {
p("data-theme-$themeId ");
}?> data-themes="<?php p(join(',', $_['enabledThemes'])) ?>">
<?php include('layout.noscript.warning.php'); ?>
<?php include('layout.initial-state.php'); ?>
<div id="skip-actions">

8
lib/private/TemplateLayout.php

@ -158,6 +158,14 @@ class TemplateLayout extends \OC_Template {
$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);

Loading…
Cancel
Save