diff options
author | Kate <26026535+provokateurin@users.noreply.github.com> | 2023-11-06 09:20:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-06 09:20:13 +0100 |
commit | 738faf4135797bae08397883befb53c3f86c3c11 (patch) | |
tree | 6e16c438fc5d9fb1556ab6479855b9bb376fb3d5 /apps/theming/lib | |
parent | 727baa225d625d62c7927ed36adbd7de22693cd7 (diff) | |
parent | e69e201af81c777aa75c739d55f0c2fe3d53236f (diff) | |
download | nextcloud-server-738faf4135797bae08397883befb53c3f86c3c11.tar.gz nextcloud-server-738faf4135797bae08397883befb53c3f86c3c11.zip |
Merge pull request #41059 from nextcloud/fix/theming/capabilities
fix(theming): Correctly expose user and admin theming
Diffstat (limited to 'apps/theming/lib')
-rw-r--r-- | apps/theming/lib/Capabilities.php | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/apps/theming/lib/Capabilities.php b/apps/theming/lib/Capabilities.php index fbb287aa410..9a1a224ed78 100644 --- a/apps/theming/lib/Capabilities.php +++ b/apps/theming/lib/Capabilities.php @@ -27,9 +27,14 @@ */ namespace OCA\Theming; +use Exception; +use OCA\Theming\AppInfo\Application; +use OCA\Theming\Service\BackgroundService; use OCP\Capabilities\IPublicCapability; use OCP\IConfig; use OCP\IURLGenerator; +use OCP\IUser; +use OCP\IUserSession; /** * Class Capabilities @@ -50,17 +55,20 @@ class Capabilities implements IPublicCapability { /** @var IConfig */ protected $config; + protected IUserSession $userSession; + /** * @param ThemingDefaults $theming * @param Util $util * @param IURLGenerator $url * @param IConfig $config */ - public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator $url, IConfig $config) { + public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator $url, IConfig $config, IUserSession $userSession) { $this->theming = $theming; $this->util = $util; $this->url = $url; $this->config = $config; + $this->userSession = $userSession; } /** @@ -86,23 +94,49 @@ class Capabilities implements IPublicCapability { * } */ 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()); + + $user = $this->userSession->getUser(); + if ($user instanceof IUser) { + /** + * Mimics the logic of generateUserBackgroundVariables() that generates the CSS variables. + * Also needs to be updated if the logic changes. + * @see \OCA\Theming\Themes\CommonThemeTrait::generateUserBackgroundVariables() + */ + $color = $this->theming->getColorPrimary(); + $colorText = $this->theming->getTextColorPrimary(); + + $backgroundImage = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT); + if ($backgroundImage === BackgroundService::BACKGROUND_CUSTOM) { + $backgroundPlain = false; + $background = $this->url->linkToRouteAbsolute('theming.userTheme.getBackground'); + } else if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$backgroundImage])) { + $backgroundPlain = false; + $background = $this->url->linkTo(Application::APP_ID, "img/background/$backgroundImage"); + } else if ($backgroundImage !== BackgroundService::BACKGROUND_DEFAULT) { + $backgroundPlain = true; + $background = $color; + } + } + 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()), |