Skip to content

Commit 623fad9

Browse files
committed
fix(theming): Correctly expose user and admin theming
Signed-off-by: jld3103 <jld3103yt@gmail.com>
1 parent 6114364 commit 623fad9

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

apps/theming/lib/Capabilities.php

+36-7
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@
2727
*/
2828
namespace OCA\Theming;
2929

30+
use Exception;
31+
use OCA\Theming\AppInfo\Application;
32+
use OCA\Theming\Service\BackgroundService;
3033
use OCP\Capabilities\IPublicCapability;
3134
use OCP\IConfig;
3235
use OCP\IURLGenerator;
36+
use OCP\IUser;
37+
use OCP\IUserSession;
3338

3439
/**
3540
* Class Capabilities
@@ -50,17 +55,20 @@ class Capabilities implements IPublicCapability {
5055
/** @var IConfig */
5156
protected $config;
5257

58+
protected IUserSession $userSession;
59+
5360
/**
5461
* @param ThemingDefaults $theming
5562
* @param Util $util
5663
* @param IURLGenerator $url
5764
* @param IConfig $config
5865
*/
59-
public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator $url, IConfig $config) {
66+
public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator $url, IConfig $config, IUserSession $userSession) {
6067
$this->theming = $theming;
6168
$this->util = $util;
6269
$this->url = $url;
6370
$this->config = $config;
71+
$this->userSession = $userSession;
6472
}
6573

6674
/**
@@ -86,23 +94,44 @@ public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator
8694
* }
8795
*/
8896
public function getCapabilities() {
97+
$color = $this->theming->getDefaultColorPrimary();
98+
$colorText = $this->theming->getDefaultTextColorPrimary();
99+
89100
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
90-
$color = $this->theming->getColorPrimary();
101+
$backgroundPlain = $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $color !== '#0082c9');
102+
$background = $backgroundPlain ? $color : $this->url->getAbsoluteURL($this->theming->getBackground());
103+
104+
$user = $this->userSession->getUser();
105+
if ($user instanceof IUser) {
106+
$color = $this->theming->getColorPrimary();
107+
$colorText = $this->theming->getTextColorPrimary();
108+
109+
$backgroundImage = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT);
110+
if ($backgroundImage === BackgroundService::BACKGROUND_CUSTOM) {
111+
$backgroundPlain = false;
112+
$background = $this->url->linkToRouteAbsolute('theming.userTheme.getBackground');
113+
} else if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$backgroundImage])) {
114+
$backgroundPlain = false;
115+
$background = $this->url->linkTo(Application::APP_ID, "img/background/$backgroundImage");
116+
} else if ($backgroundImage !== BackgroundService::BACKGROUND_DEFAULT) {
117+
$backgroundPlain = true;
118+
$background = $color;
119+
}
120+
}
121+
91122
return [
92123
'theming' => [
93124
'name' => $this->theming->getName(),
94125
'url' => $this->theming->getBaseUrl(),
95126
'slogan' => $this->theming->getSlogan(),
96127
'color' => $color,
97-
'color-text' => $this->theming->getTextColorPrimary(),
128+
'color-text' => $colorText,
98129
'color-element' => $this->util->elementColor($color),
99130
'color-element-bright' => $this->util->elementColor($color),
100131
'color-element-dark' => $this->util->elementColor($color, false),
101132
'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()),
102-
'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9') ?
103-
$this->theming->getColorPrimary() :
104-
$this->url->getAbsoluteURL($this->theming->getBackground()),
105-
'background-plain' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9'),
133+
'background' => $background,
134+
'background-plain' => $backgroundPlain,
106135
'background-default' => !$this->util->isBackgroundThemed(),
107136
'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()),
108137
'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()),

apps/theming/tests/CapabilitiesTest.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use OCP\Files\IAppData;
3737
use OCP\IConfig;
3838
use OCP\IURLGenerator;
39+
use OCP\IUserSession;
3940
use Test\TestCase;
4041

4142
/**
@@ -56,6 +57,8 @@ class CapabilitiesTest extends TestCase {
5657
/** @var Util|\PHPUnit\Framework\MockObject\MockObject */
5758
protected $util;
5859

60+
protected IUserSession $userSession;
61+
5962
/** @var Capabilities */
6063
protected $capabilities;
6164

@@ -66,7 +69,8 @@ protected function setUp(): void {
6669
$this->url = $this->getMockBuilder(IURLGenerator::class)->getMock();
6770
$this->config = $this->createMock(IConfig::class);
6871
$this->util = $this->createMock(Util::class);
69-
$this->capabilities = new Capabilities($this->theming, $this->util, $this->url, $this->config);
72+
$this->userSession = $this->createMock(IUserSession::class);
73+
$this->capabilities = new Capabilities($this->theming, $this->util, $this->url, $this->config, $this->userSession);
7074
}
7175

7276
public function dataGetCapabilities() {
@@ -165,13 +169,13 @@ public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $l
165169
->method('getSlogan')
166170
->willReturn($slogan);
167171
$this->theming->expects($this->atLeast(1))
168-
->method('getColorPrimary')
172+
->method('getDefaultColorPrimary')
169173
->willReturn($color);
170174
$this->theming->expects($this->exactly(3))
171175
->method('getLogo')
172176
->willReturn($logo);
173177
$this->theming->expects($this->once())
174-
->method('getTextColorPrimary')
178+
->method('getDefaultTextColorPrimary')
175179
->willReturn($textColor);
176180

177181
$util = new Util($this->config, $this->createMock(IAppManager::class), $this->createMock(IAppData::class), $this->createMock(ImageManager::class));

0 commit comments

Comments
 (0)