Skip to content

Commit f710c71

Browse files
committed
Add admin user customization kill switch
Signed-off-by: John Molakvoæ <[email protected]>
1 parent f85b30b commit f710c71

File tree

16 files changed

+99
-19
lines changed

16 files changed

+99
-19
lines changed

apps/theming/css/default.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
:root {
22
--color-main-background: #ffffff;
3-
--color-main-background-not-plain: #0082c9;
43
--color-main-background-rgb: 255,255,255;
54
--color-main-background-translucent: rgba(var(--color-main-background-rgb), .97);
65
--color-main-background-blur: rgba(var(--color-main-background-rgb), .8);

apps/theming/css/settings-admin.css

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/theming/css/settings-admin.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/theming/css/settings-admin.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
}
3232
form.uploadButton {
3333
width: 411px;
34+
display: flex;
35+
align-items: center;
3436
}
3537
form .theme-undo,
3638
.theme-remove-bg {
@@ -46,7 +48,14 @@
4648
visibility: visible;
4749
height: 32px;
4850
width: 32px;
51+
// right align
52+
margin-left: auto;
4953
}
54+
form .theme-undo:not([style*="display:"]) ~ .theme-remove-bg {
55+
// Only align the undo button if both are shown
56+
margin-left: 0;
57+
}
58+
5059
input[type='text']:hover + .theme-undo,
5160
input[type='text'] + .theme-undo:hover,
5261
input[type='text']:focus + .theme-undo,
@@ -61,6 +70,8 @@
6170
label span {
6271
display: inline-block;
6372
min-width: 175px;
73+
max-width: 175px;
74+
white-space: wrap;
6475
padding: 8px 0px;
6576
vertical-align: top;
6677
}
@@ -137,6 +148,15 @@
137148
#theming-preview-favicon {
138149
background-image: var(--image-favicon);
139150
}
151+
152+
#user-theming {
153+
margin-top: 44px;
154+
display: flex;
155+
& > div {
156+
max-width: 400px;
157+
margin-bottom: 44px;
158+
}
159+
}
140160
}
141161

142162
/* transition effects for theming value changes */

apps/theming/js/settings-admin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ window.addEventListener('DOMContentLoaded', function () {
173173
var el = $(this);
174174
});
175175

176+
$('#userThemingDisabled').change(function(e) {
177+
var checked = e.target.checked
178+
setThemingValue('disable-user-theming', checked ? 'yes' : 'no')
179+
});
180+
176181
function onChange(e) {
177182
var el = $(this);
178183
var setting = el.parent().find('div[data-setting]').data('setting');

apps/theming/lib/Command/UpdateConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
class UpdateConfig extends Command {
3535
public const SUPPORTED_KEYS = [
36-
'name', 'url', 'imprintUrl', 'privacyUrl', 'slogan', 'color'
36+
'name', 'url', 'imprintUrl', 'privacyUrl', 'slogan', 'color', 'disable-user-theming'
3737
];
3838

3939
public const SUPPORTED_IMAGE_KEYS = [

apps/theming/lib/Controller/ThemingController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ public function updateStylesheet($setting, $value) {
151151
$error = $this->l10n->t('The given color is invalid');
152152
}
153153
break;
154+
case 'disable-user-theming':
155+
if ($value !== "yes" && $value !== "no") {
156+
$error = $this->l10n->t('Disable-user-theming should be true or false');
157+
}
158+
break;
154159
}
155160
if ($error !== null) {
156161
return new DataResponse([

apps/theming/lib/Settings/Admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function getForm(): TemplateResponse {
8282
'images' => $this->imageManager->getCustomImages(),
8383
'imprintUrl' => $this->themingDefaults->getImprintUrl(),
8484
'privacyUrl' => $this->themingDefaults->getPrivacyUrl(),
85+
'userThemingDisabled' => $this->themingDefaults->isUserThemingDisabled(),
8586
];
8687

8788
return new TemplateResponse($this->appName, 'settings-admin', $parameters, '');

apps/theming/lib/Settings/Personal.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
use OCA\Theming\ITheme;
2929
use OCA\Theming\Service\ThemesService;
30+
use OCA\Theming\ThemingDefaults;
3031
use OCP\AppFramework\Http\TemplateResponse;
3132
use OCP\AppFramework\Services\IInitialState;
3233
use OCP\IConfig;
@@ -39,15 +40,18 @@ class Personal implements ISettings {
3940
private IConfig $config;
4041
private ThemesService $themesService;
4142
private IInitialState $initialStateService;
43+
private ThemingDefaults $themingDefaults;
4244

4345
public function __construct(string $appName,
4446
IConfig $config,
4547
ThemesService $themesService,
46-
IInitialState $initialStateService) {
48+
IInitialState $initialStateService,
49+
ThemingDefaults $themingDefaults) {
4750
$this->appName = $appName;
4851
$this->config = $config;
4952
$this->themesService = $themesService;
5053
$this->initialStateService = $initialStateService;
54+
$this->themingDefaults = $themingDefaults;
5155
}
5256

5357
public function getForm(): TemplateResponse {
@@ -72,6 +76,7 @@ public function getForm(): TemplateResponse {
7276

7377
$this->initialStateService->provideInitialState('themes', array_values($themes));
7478
$this->initialStateService->provideInitialState('enforceTheme', $enforcedTheme);
79+
$this->initialStateService->provideInitialState('isUserThemingDisabled', $this->themingDefaults->isUserThemingDisabled());
7580
Util::addScript($this->appName, 'theming-settings');
7681

7782
return new TemplateResponse($this->appName, 'settings-personal');

apps/theming/lib/Themes/DefaultTheme.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,9 @@ public function getCSSVariables(): array {
109109
$colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
110110

111111
$hasCustomLogoHeader = $this->imageManager->hasImage('logo') || $this->imageManager->hasImage('logoheader');
112-
$hasCustomPrimaryColour = !empty($this->config->getAppValue(Application::APP_ID, 'color'));
113112

114113
$variables = [
115114
'--color-main-background' => $colorMainBackground,
116-
'--color-main-background-not-plain' => $this->themingDefaults->getColorPrimary(),
117115
'--color-main-background-rgb' => $colorMainBackgroundRGB,
118116
'--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
119117
'--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)',
@@ -202,7 +200,9 @@ public function getCSSVariables(): array {
202200
'--background-invert-if-dark' => 'no',
203201
'--background-invert-if-bright' => 'invert(100%)',
204202

203+
// Default last fallback values
205204
'--image-main-background' => "url('" . $this->urlGenerator->imagePath('core', 'app-background.jpg') . "')",
205+
'--color-main-background-plain' => $this->defaultPrimaryColor,
206206
];
207207

208208
// Primary variables
@@ -211,8 +211,9 @@ public function getCSSVariables(): array {
211211
$backgroundDeleted = $this->config->getAppValue(Application::APP_ID, 'backgroundMime', '') === 'backgroundColor';
212212
// If primary as background has been request or if we have a custom primary colour
213213
// let's not define the background image
214-
if ($backgroundDeleted || $hasCustomPrimaryColour) {
215-
$variables["--image-background-plain"] = 'true';
214+
if ($backgroundDeleted && $this->themingDefaults->isUserThemingDisabled()) {
215+
$variables['--image-background-plain'] = 'true';
216+
$variables['--color-main-background-plain'] = $this->themingDefaults->getColorPrimary();
216217
}
217218

218219
// Register image variables only if custom-defined
@@ -237,9 +238,10 @@ public function getCSSVariables(): array {
237238

238239
$appManager = Server::get(IAppManager::class);
239240
$user = $this->userSession->getUser();
240-
if ($appManager->isEnabledForUser(Application::APP_ID) && $user !== null) {
241+
if (!$this->themingDefaults->isUserThemingDisabled() && $appManager->isEnabledForUser(Application::APP_ID) && $user !== null) {
241242
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
242243

244+
243245
if ($themingBackground === 'custom') {
244246
$variables['--image-main-background'] = "url('" . $this->urlGenerator->linkToRouteAbsolute('theming.userTheme.getBackground') . "')";
245247
} elseif (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground])) {

0 commit comments

Comments
 (0)