From cfdd691f28c7fb6789b98ff4e7335585514e0959 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 4 Apr 2025 10:16:34 +0200 Subject: [PATCH] fix: ensure enabled (enforced) themes are always set on template layout Signed-off-by: Ferdinand Thiessen --- apps/theming/lib/Service/ThemesService.php | 3 +-- cypress/e2e/core/404-error.cy.ts | 19 +++++++++++++++++++ lib/private/TemplateLayout.php | 17 ++++------------- 3 files changed, 24 insertions(+), 15 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 b109d023ca3ba..109050a378413 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -80,12 +80,6 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate { } else { Util::addScript('core', 'unified-search', 'core'); } - // Set body data-theme - $page->assign('enabledThemes', []); - if ($this->appManager->isEnabledForUser('theming') && class_exists('\OCA\Theming\Service\ThemesService')) { - $themesService = Server::get(\OCA\Theming\Service\ThemesService::class); - $page->assign('enabledThemes', $themesService->getEnabledThemes()); - } // Set logo link target $logoUrl = $this->config->getSystemValueString('logo_url', ''); @@ -157,13 +151,6 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate { $page->assign('appid', $appId); $page->assign('bodyid', 'body-public'); - // Set body data-theme - $page->assign('enabledThemes', []); - if ($this->appManager->isEnabledForUser('theming') && class_exists('\OCA\Theming\Service\ThemesService')) { - $themesService = Server::get(\OCA\Theming\Service\ThemesService::class); - $page->assign('enabledThemes', $themesService->getEnabledThemes()); - } - // Set logo link target $logoUrl = $this->config->getSystemValueString('logo_url', ''); $page->assign('logoUrl', $logoUrl); @@ -203,6 +190,10 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate { $page->assign('locale', $locale); $page->assign('direction', $direction); + // Set body data-theme + $themesService = Server::get(\OCA\Theming\Service\ThemesService::class); + $page->assign('enabledThemes', $themesService->getEnabledThemes()); + if ($this->config->getSystemValueBool('installed', false)) { if (empty(self::$versionHash)) { $v = $this->appManager->getAppInstalledVersions();