fix: ensure enabled themes are set on the template

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2025-04-04 09:00:43 +02:00
parent 287b520471
commit 00580b369e
No known key found for this signature in database
GPG key ID: 45FAE7268762B400
4 changed files with 32 additions and 20 deletions

View file

@ -148,8 +148,7 @@ class ThemesService {
}
/**
* Get the list of all enabled themes IDs
* for the logged-in user
* Get the list of all enabled themes IDs for the current user.
*
* @return string[]
*/

View file

@ -0,0 +1,19 @@
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
describe('404 error page', { testIsolation: true }, () => {
it('renders 404 page', () => {
cy.visit('/doesnotexist', { failOnStatusCode: false })
cy.findByRole('heading', { name: /Page not found/ })
.should('be.visible')
cy.findByRole('link', { name: /Back to Nextcloud/ })
.should('be.visible')
.click()
cy.url()
.should('match', /(\/index.php)\/login$/)
})
})

View file

@ -81,13 +81,6 @@ class TemplateLayout extends \OC_Template {
} else {
Util::addScript('core', 'unified-search', 'core');
}
// Set body data-theme
$this->assign('enabledThemes', []);
if ($this->appManager->isEnabledForUser('theming') && class_exists('\OCA\Theming\Service\ThemesService')) {
/** @var \OCA\Theming\Service\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', '');
@ -151,8 +144,6 @@ class TemplateLayout extends \OC_Template {
if ($user) {
$userDisplayName = $user->getDisplayName();
}
$theme = $this->config->getSystemValueString('enforce_theme', '');
$this->assign('enabledThemes', $theme === '' ? [] : [$theme]);
$this->assign('user_displayname', $userDisplayName);
$this->assign('user_uid', \OC_User::getUser());
} elseif ($renderAs === TemplateResponse::RENDER_AS_PUBLIC) {
@ -160,14 +151,6 @@ 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);
@ -195,10 +178,15 @@ class TemplateLayout extends \OC_Template {
} else {
parent::__construct('core', 'layout.base');
}
// Set body data-theme
$themesService = \OCP\Server::get(\OCA\Theming\Service\ThemesService::class);
$this->assign('enabledThemes', $themesService->getEnabledThemes());
// Send the language, locale, and direction to our layouts
$lang = \OC::$server->get(IFactory::class)->findLanguage();
$locale = \OC::$server->get(IFactory::class)->findLocale($lang);
$direction = \OC::$server->getL10NFactory()->getLanguageDirection($lang);
$direction = \OC::$server->get(IFactory::class)->getLanguageDirection($lang);
$lang = str_replace('_', '-', $lang);
$this->assign('language', $lang);

View file

@ -11,6 +11,7 @@ namespace Test;
use OC\InitialStateService;
use OC\TemplateLayout;
use OCA\Theming\Service\ThemesService;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
@ -45,7 +46,12 @@ class TemplateLayoutTest extends \Test\TestCase {
->willReturn('42');
$initialState = $this->createMock(InitialStateService::class);
$themesService = $this->createMock(ThemesService::class);
$themesService->expects(self::once())
->method('getEnabledThemes')
->willReturn([]);
$this->overwriteService(ThemesService::class, $themesService);
$this->overwriteService(IConfig::class, $config);
$this->overwriteService(IAppManager::class, $appManager);
$this->overwriteService(InitialStateService::class, $initialState);