Skip to content

Commit d677a3a

Browse files
authored
Merge pull request #59089 from nextcloud/fix/expand-theming-capabilities
2 parents 5a7d38b + 04d9f79 commit d677a3a

8 files changed

Lines changed: 275 additions & 39 deletions

File tree

apps/theming/lib/Capabilities.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
use OCA\Theming\AppInfo\Application;
1010
use OCA\Theming\Service\BackgroundService;
11+
use OCA\Theming\Service\ThemesService;
1112
use OCP\Capabilities\IPublicCapability;
12-
use OCP\IConfig;
13+
use OCP\Config\IUserConfig;
14+
use OCP\IAppConfig;
1315
use OCP\IURLGenerator;
1416
use OCP\IUser;
1517
use OCP\IUserSession;
@@ -21,18 +23,14 @@
2123
*/
2224
class Capabilities implements IPublicCapability {
2325

24-
/**
25-
* @param ThemingDefaults $theming
26-
* @param Util $util
27-
* @param IURLGenerator $url
28-
* @param IConfig $config
29-
*/
3026
public function __construct(
3127
protected ThemingDefaults $theming,
3228
protected Util $util,
3329
protected IURLGenerator $url,
34-
protected IConfig $config,
30+
protected IAppConfig $appConfig,
31+
protected IUserConfig $userConfig,
3532
protected IUserSession $userSession,
33+
protected ThemesService $themesService,
3634
) {
3735
}
3836

@@ -44,6 +42,8 @@ public function __construct(
4442
* name: string,
4543
* productName: string,
4644
* url: string,
45+
* imprintUrl: string,
46+
* privacyUrl: string,
4747
* slogan: string,
4848
* color: string,
4949
* color-text: string,
@@ -57,14 +57,21 @@ public function __construct(
5757
* background-default: bool,
5858
* logoheader: string,
5959
* favicon: string,
60+
* primaryColor: string,
61+
* backgroundColor: string,
62+
* defaultPrimaryColor: string,
63+
* defaultBackgroundColor: string,
64+
* inverted: bool,
65+
* cacheBuster: string,
66+
* enabledThemes: list<string>,
6067
* },
6168
* }
6269
*/
6370
public function getCapabilities() {
6471
$color = $this->theming->getDefaultColorPrimary();
6572
$colorText = $this->util->invertTextColor($color) ? '#000000' : '#ffffff';
6673

67-
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
74+
$backgroundLogo = $this->appConfig->getValueString('theming', 'backgroundMime', '');
6875
$backgroundColor = $this->theming->getColorBackground();
6976
$backgroundText = $this->theming->getTextColorBackground();
7077
$backgroundPlain = $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $backgroundColor !== BackgroundService::DEFAULT_COLOR);
@@ -80,7 +87,7 @@ public function getCapabilities() {
8087
$color = $this->theming->getColorPrimary();
8188
$colorText = $this->theming->getTextColorPrimary();
8289

83-
$backgroundImage = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT);
90+
$backgroundImage = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT);
8491
if ($backgroundImage === BackgroundService::BACKGROUND_CUSTOM) {
8592
$backgroundPlain = false;
8693
$background = $this->url->linkToRouteAbsolute('theming.userTheme.getBackground');
@@ -98,6 +105,8 @@ public function getCapabilities() {
98105
'name' => $this->theming->getName(),
99106
'productName' => $this->theming->getProductName(),
100107
'url' => $this->theming->getBaseUrl(),
108+
'imprintUrl' => $this->theming->getImprintUrl(),
109+
'privacyUrl' => $this->theming->getPrivacyUrl(),
101110
'slogan' => $this->theming->getSlogan(),
102111
'color' => $color,
103112
'color-text' => $colorText,
@@ -111,6 +120,13 @@ public function getCapabilities() {
111120
'background-default' => !$this->util->isBackgroundThemed(),
112121
'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()),
113122
'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()),
123+
'primaryColor' => $color,
124+
'backgroundColor' => $backgroundColor,
125+
'defaultPrimaryColor' => $this->theming->getDefaultColorPrimary(),
126+
'defaultBackgroundColor' => $this->theming->getDefaultColorBackground(),
127+
'inverted' => $this->util->invertTextColor($color),
128+
'cacheBuster' => $this->util->getCacheBuster(),
129+
'enabledThemes' => $this->themesService->getEnabledThemes(),
114130
],
115131
];
116132
}

apps/theming/lib/Service/JSDataService.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use OCA\Theming\ThemingDefaults;
1212
use OCA\Theming\Util;
1313

14+
/**
15+
* @deprecated since Nextcloud 34 — all properties are now exposed via Capabilities
16+
*/
1417
class JSDataService implements \JsonSerializable {
1518

1619
public function __construct(
@@ -40,10 +43,6 @@ public function jsonSerialize(): array {
4043

4144
'cacheBuster' => $this->util->getCacheBuster(),
4245
'enabledThemes' => $this->themesService->getEnabledThemes(),
43-
44-
// deprecated use primaryColor
45-
'color' => $this->themingDefaults->getColorPrimary(),
46-
'' => 'color is deprecated since Nextcloud 29, use primaryColor instead'
4746
];
4847
}
4948
}

apps/theming/lib/Service/ThemesService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ public function isEnabled(ITheme $theme): bool {
151151
/**
152152
* Get the list of all enabled themes IDs for the current user.
153153
*
154-
* @return string[]
154+
* @return list<string>
155155
*/
156-
public function getEnabledThemes(): array {
156+
public function getEnabledThemes() {
157157
$enforcedTheme = $this->config->getSystemValueString('enforce_theme', '');
158158
$user = $this->userSession->getUser();
159159
if ($user === null) {
@@ -163,6 +163,7 @@ public function getEnabledThemes(): array {
163163
return [];
164164
}
165165

166+
/** @var list<string> */
166167
$enabledThemes = json_decode($this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', '["default"]'));
167168
if ($enforcedTheme !== '') {
168169
return array_merge([$enforcedTheme], $enabledThemes);

apps/theming/lib/ThemingDefaults.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function getEntity() {
8484
return strip_tags($this->appConfig->getAppValueString(ConfigLexicon::INSTANCE_NAME, $this->entity));
8585
}
8686

87-
public function getProductName() {
87+
public function getProductName(): string {
8888
return strip_tags($this->appConfig->getAppValueString(ConfigLexicon::PRODUCT_NAME, $this->productName));
8989
}
9090

apps/theming/openapi.json

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
"name",
8282
"productName",
8383
"url",
84+
"imprintUrl",
85+
"privacyUrl",
8486
"slogan",
8587
"color",
8688
"color-text",
@@ -93,7 +95,14 @@
9395
"background-plain",
9496
"background-default",
9597
"logoheader",
96-
"favicon"
98+
"favicon",
99+
"primaryColor",
100+
"backgroundColor",
101+
"defaultPrimaryColor",
102+
"defaultBackgroundColor",
103+
"inverted",
104+
"cacheBuster",
105+
"enabledThemes"
97106
],
98107
"properties": {
99108
"name": {
@@ -105,6 +114,12 @@
105114
"url": {
106115
"type": "string"
107116
},
117+
"imprintUrl": {
118+
"type": "string"
119+
},
120+
"privacyUrl": {
121+
"type": "string"
122+
},
108123
"slogan": {
109124
"type": "string"
110125
},
@@ -143,6 +158,30 @@
143158
},
144159
"favicon": {
145160
"type": "string"
161+
},
162+
"primaryColor": {
163+
"type": "string"
164+
},
165+
"backgroundColor": {
166+
"type": "string"
167+
},
168+
"defaultPrimaryColor": {
169+
"type": "string"
170+
},
171+
"defaultBackgroundColor": {
172+
"type": "string"
173+
},
174+
"inverted": {
175+
"type": "boolean"
176+
},
177+
"cacheBuster": {
178+
"type": "string"
179+
},
180+
"enabledThemes": {
181+
"type": "array",
182+
"items": {
183+
"type": "string"
184+
}
146185
}
147186
}
148187
}

0 commit comments

Comments
 (0)