Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2022-04-29 12:54:25 +0300
committerJohn Molakvoæ <skjnldsv@protonmail.com>2022-04-30 14:40:27 +0300
commit24c5d994c7652f266f62563f11bab55defc41dae (patch)
tree584ac1f2b3cb3292690fe4c2e767bd6212601f6b /apps/theming/lib/Controller
parent77db6ced432953e2f36db28f7a981dbe997e7055 (diff)
Allow to override the default theme
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/theming/lib/Controller')
-rw-r--r--apps/theming/lib/Controller/UserThemeController.php42
1 files changed, 29 insertions, 13 deletions
diff --git a/apps/theming/lib/Controller/UserThemeController.php b/apps/theming/lib/Controller/UserThemeController.php
index ec379d2e6fa..71d78db4b3d 100644
--- a/apps/theming/lib/Controller/UserThemeController.php
+++ b/apps/theming/lib/Controller/UserThemeController.php
@@ -30,9 +30,11 @@ declare(strict_types=1);
*/
namespace OCA\Theming\Controller;
+use OCA\Theming\ITheme;
use OCA\Theming\Service\ThemesService;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
+use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCSController;
use OCP\IConfig;
use OCP\IRequest;
@@ -71,17 +73,10 @@ class UserThemeController extends OCSController {
* @throws OCSBadRequestException|PreConditionNotMetException
*/
public function enableTheme(string $themeId): DataResponse {
- if ($themeId === '' || !$themeId) {
- throw new OCSBadRequestException('Invalid theme id: ' . $themeId);
- }
+ $theme = $this->validateTheme($themeId);
- $themes = $this->themesService->getThemes();
- if (!isset($themes[$themeId])) {
- throw new OCSBadRequestException('Invalid theme id: ' . $themeId);
- }
-
// Enable selected theme
- $this->themesService->enableTheme($themes[$themeId]);
+ $this->themesService->enableTheme($theme);
return new DataResponse();
}
@@ -95,6 +90,23 @@ class UserThemeController extends OCSController {
* @throws OCSBadRequestException|PreConditionNotMetException
*/
public function disableTheme(string $themeId): DataResponse {
+ $theme = $this->validateTheme($themeId);
+
+ // Enable selected theme
+ $this->themesService->disableTheme($theme);
+ return new DataResponse();
+ }
+
+ /**
+ * Validate and return the matching ITheme
+ *
+ * Disable theme
+ *
+ * @param string $themeId the theme ID
+ * @return ITheme
+ * @throws OCSBadRequestException|PreConditionNotMetException
+ */
+ private function validateTheme(string $themeId): ITheme {
if ($themeId === '' || !$themeId) {
throw new OCSBadRequestException('Invalid theme id: ' . $themeId);
}
@@ -103,9 +115,13 @@ class UserThemeController extends OCSController {
if (!isset($themes[$themeId])) {
throw new OCSBadRequestException('Invalid theme id: ' . $themeId);
}
-
- // Enable selected theme
- $this->themesService->disableTheme($themes[$themeId]);
- return new DataResponse();
+
+ // If trying to toggle another theme but this is enforced
+ if ($this->config->getSystemValueString('enforce_theme', '') !== ''
+ && $themes[$themeId]->getType() === ITheme::TYPE_THEME) {
+ throw new OCSForbiddenException('Theme switching is disabled');
+ }
+
+ return $themes[$themeId];
}
}