From 837eb4504ca24e53bea360eb471bf0c84fd2f406 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 11 Oct 2023 19:01:59 +0200 Subject: [PATCH] fix(theming): Stop leaking user theme into capabilities Signed-off-by: jld3103 --- apps/theming/lib/Capabilities.php | 15 +++++++++------ apps/theming/tests/CapabilitiesTest.php | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/theming/lib/Capabilities.php b/apps/theming/lib/Capabilities.php index fbb287aa41067..b63401b7c10a6 100644 --- a/apps/theming/lib/Capabilities.php +++ b/apps/theming/lib/Capabilities.php @@ -86,23 +86,26 @@ public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator * } */ public function getCapabilities() { + $color = $this->theming->getDefaultColorPrimary(); + $colorText = $this->theming->getDefaultTextColorPrimary(); + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', ''); - $color = $this->theming->getColorPrimary(); + $backgroundPlain = $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $color !== '#0082c9'); + $background = $backgroundPlain ? $color : $this->url->getAbsoluteURL($this->theming->getBackground()); + return [ 'theming' => [ 'name' => $this->theming->getName(), 'url' => $this->theming->getBaseUrl(), 'slogan' => $this->theming->getSlogan(), 'color' => $color, - 'color-text' => $this->theming->getTextColorPrimary(), + 'color-text' => $colorText, 'color-element' => $this->util->elementColor($color), 'color-element-bright' => $this->util->elementColor($color), 'color-element-dark' => $this->util->elementColor($color, false), 'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()), - 'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9') ? - $this->theming->getColorPrimary() : - $this->url->getAbsoluteURL($this->theming->getBackground()), - 'background-plain' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9'), + 'background' => $background, + 'background-plain' => $backgroundPlain, 'background-default' => !$this->util->isBackgroundThemed(), 'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()), 'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()), diff --git a/apps/theming/tests/CapabilitiesTest.php b/apps/theming/tests/CapabilitiesTest.php index 1a2d01d69d124..6e69e3ed6d027 100644 --- a/apps/theming/tests/CapabilitiesTest.php +++ b/apps/theming/tests/CapabilitiesTest.php @@ -165,13 +165,13 @@ public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $l ->method('getSlogan') ->willReturn($slogan); $this->theming->expects($this->atLeast(1)) - ->method('getColorPrimary') + ->method('getDefaultColorPrimary') ->willReturn($color); $this->theming->expects($this->exactly(3)) ->method('getLogo') ->willReturn($logo); $this->theming->expects($this->once()) - ->method('getTextColorPrimary') + ->method('getDefaultTextColorPrimary') ->willReturn($textColor); $util = new Util($this->config, $this->createMock(IAppManager::class), $this->createMock(IAppData::class), $this->createMock(ImageManager::class));