diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-05-20 15:59:42 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-05-21 20:36:32 +0200 |
commit | f19d586839edc9421b3748d17a5036f3ae83e835 (patch) | |
tree | 580a76d84580ae063f679ed1733dcbaf168debdd /apps/theming | |
parent | 538a04968a24f645b12ca2647952a5b73ebc3eac (diff) | |
download | nextcloud-server-f19d586839edc9421b3748d17a5036f3ae83e835.tar.gz nextcloud-server-f19d586839edc9421b3748d17a5036f3ae83e835.zip |
fix(theming): Add some strict checking for userId
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/theming')
-rw-r--r-- | apps/theming/lib/Service/BackgroundService.php | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/apps/theming/lib/Service/BackgroundService.php b/apps/theming/lib/Service/BackgroundService.php index cdaff2372a8..4772239b0c9 100644 --- a/apps/theming/lib/Service/BackgroundService.php +++ b/apps/theming/lib/Service/BackgroundService.php @@ -41,6 +41,7 @@ use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; use OCP\Lock\LockedException; use OCP\PreConditionNotMetException; +use RuntimeException; class BackgroundService { public const DEFAULT_COLOR = '#00679e'; @@ -231,6 +232,9 @@ class BackgroundService { * @throws NoUserException */ public function setFileBackground($path): void { + if ($this->userId === null) { + throw new RuntimeException('No currently logged-in user'); + } $userFolder = $this->rootFolder->getUserFolder($this->userId); /** @var File $file */ @@ -251,6 +255,9 @@ class BackgroundService { } public function setShippedBackground($fileName): void { + if ($this->userId === null) { + throw new RuntimeException('No currently logged-in user'); + } if (!array_key_exists($fileName, self::SHIPPED_BACKGROUNDS)) { throw new InvalidArgumentException('The given file name is invalid'); } @@ -263,6 +270,9 @@ class BackgroundService { * Set the background to color only */ public function setColorBackground(string $color): void { + if ($this->userId === null) { + throw new RuntimeException('No currently logged-in user'); + } if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) { throw new InvalidArgumentException('The given color is invalid'); } @@ -271,6 +281,9 @@ class BackgroundService { } public function deleteBackgroundImage(): void { + if ($this->userId === null) { + throw new RuntimeException('No currently logged-in user'); + } $this->config->setUserValue($this->userId, Application::APP_ID, 'background_image', self::BACKGROUND_COLOR); } @@ -314,7 +327,7 @@ class BackgroundService { /** * Small helper to ensure one channel is returned as 8byte hex */ - function toHex(int $channel) { + function toHex(int $channel): string { $hex = dechex($channel); return match (strlen($hex)) { 0 => '00', |