From 7aafcbf80ddc95369e5fa37c85249936150e8db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 17 Nov 2023 08:51:32 +0100 Subject: [PATCH] fix: Avoid conflicts on deck attachments folder name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/ConfigService.php | 8 ++++++++ lib/Service/FilesAppService.php | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index c0732922d..b6fd00b75 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -230,4 +230,12 @@ class ConfigService { return $this->config->getUserValue($userId ?? $this->getUserId(), 'deck', 'attachment_folder', '/Deck'); } + + public function setAttachmentFolder(?string $userId = null, string $path): void { + if ($userId === null && $this->getUserId() === null) { + throw new NoPermissionException('Must be logged in get the attachment folder'); + } + + $this->config->setUserValue($userId ?? $this->getUserId(), 'deck', 'attachment_folder', $path); + } } diff --git a/lib/Service/FilesAppService.php b/lib/Service/FilesAppService.php index 09e0c16da..80b82ee65 100644 --- a/lib/Service/FilesAppService.php +++ b/lib/Service/FilesAppService.php @@ -31,6 +31,7 @@ use OCA\Deck\Sharing\DeckShareProvider; use OCA\Deck\StatusException; use OCP\AppFramework\Http\StreamResponse; use OCP\Constants; +use OCP\Files\Folder; use OCP\Files\IMimeTypeDetector; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; @@ -186,10 +187,20 @@ class FilesAppService implements IAttachmentService, ICustomAttachmentService { $userFolder = $this->rootFolder->getUserFolder($this->userId); try { $folder = $userFolder->get($this->configService->getAttachmentFolder()); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $folder = $userFolder->newFolder($this->configService->getAttachmentFolder()); } + if ($folder->isShared()) { + $folderName = $userFolder->getNonExistingName($this->configService->getAttachmentFolder()); + $folder = $userFolder->newFolder($folderName); + $this->configService->setAttachmentFolder($this->userId, $folderName); + } + + if (!$folder instanceof Folder || $folder->isShared()) { + throw new NotFoundException('No target folder found'); + } + $fileName = $folder->getNonExistingName($fileName); $target = $folder->newFile($fileName); $content = fopen($file['tmp_name'], 'rb');