diff --git a/lib/Exceptions/ConflictException.php b/lib/Exceptions/ConflictException.php index b44bff031..53c33601c 100644 --- a/lib/Exceptions/ConflictException.php +++ b/lib/Exceptions/ConflictException.php @@ -21,16 +21,24 @@ * */ -namespace OCA\Deck; +namespace OCA\Deck\Exceptions; +use OCA\Deck\StatusException; -class ConflictException extends \Exception { +class ConflictException extends StatusException { - public function __construct($message) { + private $data; + + public function __construct($message, $data = null) { parent::__construct($message); + $this->data = $data; } public function getStatus() { return 409; } + + public function getData() { + return $this->data; + } } \ No newline at end of file diff --git a/lib/Middleware/ExceptionMiddleware.php b/lib/Middleware/ExceptionMiddleware.php index a4f0610ee..416ef105a 100644 --- a/lib/Middleware/ExceptionMiddleware.php +++ b/lib/Middleware/ExceptionMiddleware.php @@ -25,6 +25,7 @@ namespace OCA\Deck\Middleware; use OCA\Deck\Controller\PageController; use OCA\Deck\StatusException; +use OCA\Deck\Exceptions\ConflictException; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Middleware; use OCP\AppFramework\Http\JSONResponse; @@ -63,6 +64,17 @@ class ExceptionMiddleware extends Middleware { * @throws \Exception */ public function afterException($controller, $methodName, \Exception $exception) { + if ($exception instanceof ConflictException) { + if ($this->config->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { + $this->logger->logException($exception); + } + return new JSONResponse([ + 'status' => $exception->getStatus(), + 'message' => $exception->getMessage(), + 'data' => $exception->getData(), + ], $exception->getStatus()); + } + if ($exception instanceof StatusException) { if ($this->config->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { $this->logger->logException($exception); diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index 02f3ab6bc..0aafd45ce 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -26,6 +26,7 @@ namespace OCA\Deck\Service; use OC\Security\CSP\ContentSecurityPolicyManager; use OCA\Deck\Db\Attachment; use OCA\Deck\StatusException; +use OCA\Deck\Exceptions\ConflictException; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\EmptyContentSecurityPolicy; use OCP\AppFramework\Http\FileDisplayResponse; @@ -42,7 +43,7 @@ use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; use OCP\IRequest; -use OCP\Deck\ConflictException; + class FileService implements IAttachmentService { @@ -154,7 +155,7 @@ class FileService implements IAttachmentService { $folder = $this->getFolder($attachment); $fileName = $file['name']; if ($folder->fileExists($fileName)) { - throw new ConflictException('File already exists.'); + throw new ConflictException('File already exists.', $attachment); } $target = $folder->newFile($fileName); diff --git a/src/components/card/CardSidebarTabAttachments.vue b/src/components/card/CardSidebarTabAttachments.vue index 8f53a2d56..de401f96d 100644 --- a/src/components/card/CardSidebarTabAttachments.vue +++ b/src/components/card/CardSidebarTabAttachments.vue @@ -45,17 +45,38 @@ type="file" style="display: none;" @change="onLocalAttachmentSelected"> + + + + {{ t('deck', 'File already exists') }} + + {{ t('deck', 'A file with the name') }} + {{ file.name }} + {{ t('deck', 'already exists.') }} + + + {{ t('deck', 'Do you want to overwrite it?') }} + + + {{ t('deck', 'Yes') }} + + + {{ t('deck', 'No') }} + + + @@ -117,4 +151,16 @@ export default { height: 32px; background-size: contain; } + .modal__content { + width: 25vw; + min-width: 250px; + height: 120px; + text-align: center; + margin: 20px 20px 60px 20px; + } + + .modal__content button { + float: right; + margin: 40px 3px 3px 0; + } diff --git a/src/services/AttachmentApi.js b/src/services/AttachmentApi.js index 751ccdca4..66cab0934 100644 --- a/src/services/AttachmentApi.js +++ b/src/services/AttachmentApi.js @@ -38,7 +38,7 @@ export class AttachmentApi { } async createAttachment({ cardId, formData }) { - const response = await axios({ + const response = await axios({ method: 'POST', url: this.url(`/cards/${cardId}/attachment`), data: formData, @@ -46,6 +46,15 @@ export class AttachmentApi { return response.data } + async updateAttachment({ cardId, attachmentId, formData }) { + const response = await axios({ + method: 'PUT', + url: this.url(`/cards/${cardId}/attachment/${attachmentId}`), + data: formData, + }) + return response.data + } + async deleteAttachment(attachment) { await axios({ method: 'DELETE', diff --git a/src/store/attachment.js b/src/store/attachment.js index ffa3c21d2..f8651f42a 100644 --- a/src/store/attachment.js +++ b/src/store/attachment.js @@ -47,6 +47,10 @@ export default { } }, + updateAttachment(state, { cardId, attachment }) { + Vue.set(state.attachments, cardId, attachment) + }, + deleteAttachment(state, deletedAttachment) { const existingIndex = state.attachments[deletedAttachment.cardId].findIndex(a => a.id === deletedAttachment.id) if (existingIndex !== -1) { @@ -67,6 +71,11 @@ export default { commit('cardIncreaseAttachmentCount', cardId) }, + async updateAttachment({ commit }, { cardId, attachmentId, formData }) { + const attachment = await apiClient.updateAttachment({ cardId, attachmentId, formData }) + commit('updateAttachment', { cardId, attachment }) + }, + async deleteAttachment({ commit }, attachment) { await apiClient.deleteAttachment(attachment) commit('deleteAttachment', attachment)
+ {{ t('deck', 'A file with the name') }} + {{ file.name }} + {{ t('deck', 'already exists.') }} +
+ {{ t('deck', 'Do you want to overwrite it?') }} +