Skip to content

Commit

Permalink
Merge pull request #5707 from nextcloud/backport/5703/stable25
Browse files Browse the repository at this point in the history
[stable25] fix: Avoid conflicts on deck attachments folder name
  • Loading branch information
juliusknorr authored Jul 12, 2024
2 parents 6dee849 + 54b62fe commit 15d7098
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [14.x]
node-version: [16.x]
# containers: [1, 2, 3]
php-versions: [ '7.4' ]
databases: [ 'sqlite' ]
Expand Down
8 changes: 8 additions & 0 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,12 @@ public function getAttachmentFolder(string $userId = null): string {

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);
}
}
11 changes: 11 additions & 0 deletions lib/Service/FilesAppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -190,6 +191,16 @@ public function create(Attachment $attachment) {
$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');
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/base-query-count.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
68024
79470

0 comments on commit 15d7098

Please sign in to comment.