Skip to content

Commit

Permalink
Merge pull request #50076 from Koc/bugfix/fix-enforce-theme-for-publi…
Browse files Browse the repository at this point in the history
…c-links

fix: Apply enforce theme config for anonymous users as well
  • Loading branch information
sorbaugh authored Jan 10, 2025
2 parents 43ae9e0 + 438528b commit b2c7491
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 4 additions & 1 deletion apps/theming/lib/Service/ThemesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 8 additions & 6 deletions core/templates/layout.public.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
<?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">
Expand Down Expand Up @@ -81,11 +83,11 @@
<main id="content" class="app-<?php p($_['appid']) ?>">
<h1 class="hidden-visually">
<?php
if (isset($template) && $template->getHeaderTitle() !== '') {
p($template->getHeaderTitle());
} else {
p($theme->getName());
} ?>
if (isset($template) && $template->getHeaderTitle() !== '') {
p($template->getHeaderTitle());
} else {
p($theme->getName());
} ?>
</h1>
<?php print_unescaped($_['content']); ?>
</main>
Expand Down
8 changes: 8 additions & 0 deletions lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b2c7491

Please sign in to comment.