From 00580b369e770221edc6670a06de4c2d03832fdf Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 4 Apr 2025 09:00:43 +0200 Subject: [PATCH] fix: ensure enabled themes are set on the template Signed-off-by: Ferdinand Thiessen --- apps/theming/lib/Service/ThemesService.php | 3 +-- cypress/e2e/core/404-error.cy.ts | 19 +++++++++++++++++ lib/private/TemplateLayout.php | 24 ++++++---------------- tests/lib/TemplateLayoutTest.php | 6 ++++++ 4 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 cypress/e2e/core/404-error.cy.ts diff --git a/apps/theming/lib/Service/ThemesService.php b/apps/theming/lib/Service/ThemesService.php index 39a8eeff41052..37ea47f80d8aa 100644 --- a/apps/theming/lib/Service/ThemesService.php +++ b/apps/theming/lib/Service/ThemesService.php @@ -148,8 +148,7 @@ public function isEnabled(ITheme $theme): bool { } /** - * 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[] */ diff --git a/cypress/e2e/core/404-error.cy.ts b/cypress/e2e/core/404-error.cy.ts new file mode 100644 index 0000000000000..b24562933e8bb --- /dev/null +++ b/cypress/e2e/core/404-error.cy.ts @@ -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$/) + }) +}) diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index ad321dae0fc4d..9bb12c804d735 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -81,13 +81,6 @@ public function __construct($renderAs, $appId = '') { } 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 @@ public function __construct($renderAs, $appId = '') { 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 @@ 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); @@ -195,10 +178,15 @@ public function __construct($renderAs, $appId = '') { } 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); diff --git a/tests/lib/TemplateLayoutTest.php b/tests/lib/TemplateLayoutTest.php index 405f1df7330d2..044c32c347a5e 100644 --- a/tests/lib/TemplateLayoutTest.php +++ b/tests/lib/TemplateLayoutTest.php @@ -11,6 +11,7 @@ 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 @@ public function testVersionHash($path, $file, $installed, $debug, $expected): vo ->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);