diff --git a/lib/Controller/AttachmentApiController.php b/lib/Controller/AttachmentApiController.php index e2c044e1a..cf027c064 100644 --- a/lib/Controller/AttachmentApiController.php +++ b/lib/Controller/AttachmentApiController.php @@ -45,7 +45,7 @@ class AttachmentApiController extends ApiController { * */ public function getAll() { - $attachment = $this->attachmentService->findAll($this->request->getParam('cardId')); + $attachment = $this->attachmentService->findAll($this->request->getParam('cardId'), true); return new DataResponse($attachment, HTTP::STATUS_OK); } diff --git a/lib/Controller/AttachmentController.php b/lib/Controller/AttachmentController.php index ea31f194a..d595dc2b8 100644 --- a/lib/Controller/AttachmentController.php +++ b/lib/Controller/AttachmentController.php @@ -42,7 +42,7 @@ class AttachmentController extends Controller { * @NoAdminRequired */ public function getAll($cardId) { - return $this->attachmentService->findAll($cardId); + return $this->attachmentService->findAll($cardId, true); } /** diff --git a/lib/Db/AttachmentMapper.php b/lib/Db/AttachmentMapper.php index 2ccae3be8..00a7c61d7 100644 --- a/lib/Db/AttachmentMapper.php +++ b/lib/Db/AttachmentMapper.php @@ -81,6 +81,22 @@ class AttachmentMapper extends DeckMapper implements IPermissionMapper { return $this->mapRowToEntity($row); } + public function findByData($cardId, $data) { + $qb = $this->db->getQueryBuilder(); + $qb->select('*') + ->from('deck_attachment') + ->where($qb->expr()->eq('card_id', $qb->createNamedParameter($cardId, IQueryBuilder::PARAM_INT))) + ->andWhere($qb->expr()->eq('data', $qb->createNamedParameter($data, IQueryBuilder::PARAM_STR))); + $cursor = $qb->execute(); + $row = $cursor->fetch(PDO::FETCH_ASSOC); + if($row === false) { + $cursor->closeCursor(); + throw new DoesNotExistException('Did expect one result but found none when executing' . $qb); + } + $cursor->closeCursor(); + return $this->mapRowToEntity($row); + } + /** * Find all attachments for a card * diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index 0aafd45ce..1e4216591 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -25,6 +25,7 @@ namespace OCA\Deck\Service; use OC\Security\CSP\ContentSecurityPolicyManager; use OCA\Deck\Db\Attachment; +use OCA\Deck\Db\AttachmentMapper; use OCA\Deck\StatusException; use OCA\Deck\Exceptions\ConflictException; use OCP\AppFramework\Http\ContentSecurityPolicy; @@ -53,6 +54,7 @@ class FileService implements IAttachmentService { private $logger; private $rootFolder; private $config; + private $attachmentMapper; public function __construct( IL10N $l10n, @@ -60,7 +62,8 @@ class FileService implements IAttachmentService { IRequest $request, ILogger $logger, IRootFolder $rootFolder, - IConfig $config + IConfig $config, + AttachmentMapper $attachmentMapper ) { $this->l10n = $l10n; $this->appData = $appData; @@ -68,6 +71,7 @@ class FileService implements IAttachmentService { $this->logger = $logger; $this->rootFolder = $rootFolder; $this->config = $config; + $this->attachmentMapper = $attachmentMapper; } /** @@ -155,6 +159,7 @@ class FileService implements IAttachmentService { $folder = $this->getFolder($attachment); $fileName = $file['name']; if ($folder->fileExists($fileName)) { + $attachment = $this->attachmentMapper->findByData($attachment->getCardId(), $fileName); throw new ConflictException('File already exists.', $attachment); } diff --git a/package-lock.json b/package-lock.json index eeda19e46..36ff598c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3442,6 +3442,22 @@ "resolved": "https://registry.npmjs.org/@nextcloud/browserslist-config/-/browserslist-config-1.0.0.tgz", "integrity": "sha512-f+sKpdLZXkODV+OY39K1M+Spmd4RgxmtEXmNn4Bviv4R7uBFHXuw+JX9ZdfDeOryfHjJ/TRQxQEp0GMpBwZFUw==" }, + "@nextcloud/dialogs": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@nextcloud/dialogs/-/dialogs-1.2.1.tgz", + "integrity": "sha512-v+nnlqdOUpqumD51Fkjo1V9W/xImW7GcY29Iq1ErSDCmkhrS4pk9YDYrZO86teey+pT5nZ0gdGAtiU+LNFQgzw==", + "requires": { + "core-js": "3.6.4", + "toastify-js": "^1.6.2" + }, + "dependencies": { + "core-js": { + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.6.4.tgz", + "integrity": "sha512-4paDGScNgZP2IXXilaffL9X7968RuvwlkK3xWtZRVqgd8SYNiVKRJvkFd1aqqEuPfN7E68ZHEp9hDj6lHj4Hyw==" + } + } + }, "@nextcloud/event-bus": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@nextcloud/event-bus/-/event-bus-1.1.2.tgz", @@ -17828,6 +17844,11 @@ } } }, + "toastify-js": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/toastify-js/-/toastify-js-1.7.0.tgz", + "integrity": "sha512-GmPy4zJ/ulCfmCHlfCtgcB+K2xhx2AXW3T/ZZOSjyjaIGevhz+uvR8HSCTay/wBq4tt2mUnBqlObP1sSWGlsnQ==" + }, "tough-cookie": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-3.0.1.tgz", diff --git a/package.json b/package.json index f6f2c22d8..2888b99a7 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@nextcloud/auth": "^1.2.1", "@nextcloud/axios": "^1.3.1", "@nextcloud/l10n": "^1.1.0", + "@nextcloud/dialogs": "^1.2.1", "@nextcloud/moment": "^1.1.0", "@nextcloud/router": "^1.0.0", "@nextcloud/vue": "^1.4.0", diff --git a/src/components/card/CardSidebarTabAttachments.vue b/src/components/card/CardSidebarTabAttachments.vue index de401f96d..3ebc600f2 100644 --- a/src/components/card/CardSidebarTabAttachments.vue +++ b/src/components/card/CardSidebarTabAttachments.vue @@ -22,22 +22,6 @@