summaryrefslogtreecommitdiffstats
path: root/apps/theming/lib
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2022-10-14 11:19:00 +0200
committerVincent Petry <vincent@nextcloud.com>2022-10-14 16:18:37 +0200
commite4ff84d468acf3c0e2d497412b7192651bbd4e23 (patch)
tree66c789af19efbd536d3ff7a6035f087cca9639ed /apps/theming/lib
parent95d45c20580683a7ed332b2e313ee42b8b728bc7 (diff)
downloadnextcloud-server-e4ff84d468acf3c0e2d497412b7192651bbd4e23.tar.gz
nextcloud-server-e4ff84d468acf3c0e2d497412b7192651bbd4e23.zip
Scope the appdata theming storage for global and users
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/theming/lib')
-rw-r--r--apps/theming/lib/Controller/UserThemeController.php7
-rw-r--r--apps/theming/lib/ImageManager.php29
-rw-r--r--apps/theming/lib/Listener/BeforeTemplateRenderedListener.php2
-rw-r--r--apps/theming/lib/Service/BackgroundService.php28
4 files changed, 42 insertions, 24 deletions
diff --git a/apps/theming/lib/Controller/UserThemeController.php b/apps/theming/lib/Controller/UserThemeController.php
index 091331706a7..31acfc1d97c 100644
--- a/apps/theming/lib/Controller/UserThemeController.php
+++ b/apps/theming/lib/Controller/UserThemeController.php
@@ -157,6 +157,7 @@ class UserThemeController extends OCSController {
*/
public function setBackground(string $type = 'default', string $value = ''): JSONResponse {
$currentVersion = (int)$this->config->getUserValue($this->userId, Application::APP_ID, 'backgroundVersion', '0');
+
try {
switch ($type) {
case 'shipped':
@@ -179,14 +180,14 @@ class UserThemeController extends OCSController {
} catch (\Throwable $e) {
return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
}
+
$currentVersion++;
$this->config->setUserValue($this->userId, Application::APP_ID, 'backgroundVersion', (string)$currentVersion);
- // FIXME replace with user-specific cachebuster increase https://github.com/nextcloud/server/issues/34472
- $this->themingDefaults->increaseCacheBuster();
+
return new JSONResponse([
'type' => $type,
'value' => $value,
- 'version' => $this->config->getUserValue($this->userId, Application::APP_ID, 'backgroundVersion', $currentVersion)
+ 'version' => $currentVersion,
]);
}
}
diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php
index 6f9892af10e..8a84ed55302 100644
--- a/apps/theming/lib/ImageManager.php
+++ b/apps/theming/lib/ImageManager.php
@@ -66,14 +66,13 @@ class ImageManager {
IURLGenerator $urlGenerator,
ICacheFactory $cacheFactory,
ILogger $logger,
- ITempManager $tempManager
- ) {
+ ITempManager $tempManager) {
$this->config = $config;
- $this->appData = $appData;
$this->urlGenerator = $urlGenerator;
$this->cacheFactory = $cacheFactory;
$this->logger = $logger;
$this->tempManager = $tempManager;
+ $this->appData = $appData;
}
public function getImageUrl(string $key, bool $useSvg = true): string {
@@ -106,7 +105,7 @@ class ImageManager {
*/
public function getImage(string $key, bool $useSvg = true): ISimpleFile {
$logo = $this->config->getAppValue('theming', $key . 'Mime', '');
- $folder = $this->appData->getFolder('images');
+ $folder = $this->getRootFolder()->getFolder('images');
if ($logo === '' || !$folder->fileExists($key)) {
throw new NotFoundException();
}
@@ -158,9 +157,9 @@ class ImageManager {
public function getCacheFolder(): ISimpleFolder {
$cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
try {
- $folder = $this->appData->getFolder($cacheBusterValue);
+ $folder = $this->getRootFolder()->getFolder($cacheBusterValue);
} catch (NotFoundException $e) {
- $folder = $this->appData->newFolder($cacheBusterValue);
+ $folder = $this->getRootFolder()->newFolder($cacheBusterValue);
$this->cleanup();
}
return $folder;
@@ -202,13 +201,13 @@ class ImageManager {
public function delete(string $key): void {
/* ignore exceptions, since we don't want to fail hard if something goes wrong during cleanup */
try {
- $file = $this->appData->getFolder('images')->getFile($key);
+ $file = $this->getRootFolder()->getFolder('images')->getFile($key);
$file->delete();
} catch (NotFoundException $e) {
} catch (NotPermittedException $e) {
}
try {
- $file = $this->appData->getFolder('images')->getFile($key . '.png');
+ $file = $this->getRootFolder()->getFolder('images')->getFile($key . '.png');
$file->delete();
} catch (NotFoundException $e) {
} catch (NotPermittedException $e) {
@@ -219,9 +218,9 @@ class ImageManager {
$this->delete($key);
try {
- $folder = $this->appData->getFolder('images');
+ $folder = $this->getRootFolder()->getFolder('images');
} catch (NotFoundException $e) {
- $folder = $this->appData->newFolder('images');
+ $folder = $this->getRootFolder()->newFolder('images');
}
$target = $folder->newFile($key);
@@ -288,7 +287,7 @@ class ImageManager {
*/
public function cleanup() {
$currentFolder = $this->getCacheFolder();
- $folders = $this->appData->getDirectoryListing();
+ $folders = $this->getRootFolder()->getDirectoryListing();
foreach ($folders as $folder) {
if ($folder->getName() !== 'images' && $folder->getName() !== $currentFolder->getName()) {
$folder->delete();
@@ -316,4 +315,12 @@ class ImageManager {
$cache->set('shouldReplaceIcons', $value);
return $value;
}
+
+ private function getRootFolder(): ISimpleFolder {
+ try {
+ return $this->appData->getFolder('global');
+ } catch (NotFoundException $e) {
+ return $this->appData->newFolder('global');
+ }
+ }
}
diff --git a/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php b/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php
index 1d28a1d4399..bbe7963f99e 100644
--- a/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php
+++ b/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php
@@ -91,7 +91,7 @@ class BeforeTemplateRenderedListener implements IEventListener {
$this->initialState->provideInitialState(
'backgroundVersion',
- $this->config->getUserValue($userId, Application::APP_ID, 'backgroundVersion', 0),
+ (int)$this->config->getUserValue($userId, Application::APP_ID, 'backgroundVersion', '0'),
);
$this->initialState->provideInitialState(
diff --git a/apps/theming/lib/Service/BackgroundService.php b/apps/theming/lib/Service/BackgroundService.php
index 36623735728..3daac7e7215 100644
--- a/apps/theming/lib/Service/BackgroundService.php
+++ b/apps/theming/lib/Service/BackgroundService.php
@@ -136,19 +136,19 @@ class BackgroundService {
private string $userId;
private IAppDataFactory $appDataFactory;
- public function __construct(
- IRootFolder $rootFolder,
- IAppDataFactory $appDataFactory,
- IConfig $config,
- ?string $userId
- ) {
+ public function __construct(IRootFolder $rootFolder,
+ IAppData $appData,
+ IConfig $config,
+ ?string $userId,
+ IAppDataFactory $appDataFactory) {
if ($userId === null) {
return;
}
+
$this->rootFolder = $rootFolder;
- $this->appData = $appDataFactory->get(Application::APP_ID);
$this->config = $config;
$this->userId = $userId;
+ $this->appData = $appData;
$this->appDataFactory = $appDataFactory;
}
@@ -167,12 +167,15 @@ class BackgroundService {
public function setFileBackground($path): void {
$this->config->setUserValue($this->userId, Application::APP_ID, 'background', 'custom');
$userFolder = $this->rootFolder->getUserFolder($this->userId);
+
/** @var File $file */
$file = $userFolder->get($path);
$image = new \OCP\Image();
+
if ($image->loadFromFileHandle($file->fopen('r')) === false) {
throw new InvalidArgumentException('Invalid image file');
}
+
$this->getAppDataFolder()->newFile('background.jpg', $file->fopen('r'));
}
@@ -207,14 +210,21 @@ class BackgroundService {
}
/**
+ * Storing the data in appdata/theming/users/USERID
+ *
* @return ISimpleFolder
* @throws NotPermittedException
*/
private function getAppDataFolder(): ISimpleFolder {
try {
- return $this->appData->getFolder($this->userId);
+ $rootFolder = $this->appData->getFolder('users');
+ } catch (NotFoundException $e) {
+ $rootFolder = $this->appData->newFolder('users');
+ }
+ try {
+ return $rootFolder->getFolder($this->userId);
} catch (NotFoundException $e) {
- return $this->appData->newFolder($this->userId);
+ return $rootFolder->newFolder($this->userId);
}
}
}