From 454b8d3dbfcc18cc97021b02bd1e4867a331670e Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Tue, 5 Nov 2024 16:03:58 -0300 Subject: [PATCH] feat: make possible delete file too Signed-off-by: Vitor Mattos --- lib/Controller/FileController.php | 42 +++++++++++++++++++ lib/Service/FileService.php | 16 +++++++ src/store/files.js | 7 +++- .../FilesList/FileEntry/FileEntryActions.vue | 27 ++++++++---- 4 files changed, 83 insertions(+), 9 deletions(-) diff --git a/lib/Controller/FileController.php b/lib/Controller/FileController.php index e9b2757375..b91f13e9f1 100644 --- a/lib/Controller/FileController.php +++ b/lib/Controller/FileController.php @@ -391,4 +391,46 @@ public function save(array $file, string $name = '', array $settings = []): Data ); } } + + /** + * Delete File + * + * This will delete the file and all data + * + * @param integer $fileId Node id of a Nextcloud file + * @return DataResponse|DataResponse|DataResponse + * + * 200: OK + * 401: Failed + * 422: Failed + */ + #[NoAdminRequired] + #[NoCSRFRequired] + #[RequireManager] + #[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/file/file_id/{fileId}', requirements: ['apiVersion' => '(v1)'])] + public function deleteAllRequestSignatureUsingFileId(int $fileId): DataResponse { + try { + $data = [ + 'userManager' => $this->userSession->getUser(), + 'file' => [ + 'fileId' => $fileId + ] + ]; + $this->validateHelper->validateExistingFile($data); + $this->fileService->delete($fileId); + } catch (\Throwable $th) { + return new DataResponse( + [ + 'message' => $th->getMessage(), + ], + Http::STATUS_UNAUTHORIZED + ); + } + return new DataResponse( + [ + 'message' => $this->l10n->t('Success') + ], + Http::STATUS_OK + ); + } } diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index 57ce58d6cc..9d967d2774 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -591,4 +591,20 @@ public function getMyLibresignFile(int $nodeId): File { ], ); } + + public function delete(int $fileId): void { + $file = $this->fileMapper->getByFileId($fileId); + $this->fileElementService->deleteVisibleElements($file->getId()); + $list = $this->signRequestMapper->getByFileId($file->getId()); + foreach ($list as $signRequest) { + $this->signRequestMapper->delete($signRequest); + } + $this->fileMapper->delete($file); + if ($file->getSignedNodeId()) { + $signedNextcloudFile = $this->folderService->getFileById($file->getSignedNodeId()); + $signedNextcloudFile->delete(); + } + $nextcloudFile = $this->folderService->getFileById($fileId); + $nextcloudFile->delete(); + } } diff --git a/src/store/files.js b/src/store/files.js index 82d05b32af..c4d983f5af 100644 --- a/src/store/files.js +++ b/src/store/files.js @@ -210,10 +210,13 @@ export const useFilesStore = function(...args) { this.files[this.selectedNodeId].signers.filter((i) => i.identify !== signer.identify), ) }, - async delete(file) { + async delete(file, deleteFile) { file = this.getFile(file) if (file?.uuid !== undefined) { - await axios.delete(generateOcsUrl('/apps/libresign/api/v1/sign/file_id/{fileId}', { + const url = deleteFile + ? '/apps/libresign/api/v1/file/file_id/{fileId}' + : '/apps/libresign/api/v1/sign/file_id/{fileId}' + await axios.delete(generateOcsUrl(url, { fileId: file.nodeId, })) } diff --git a/src/views/FilesList/FileEntry/FileEntryActions.vue b/src/views/FilesList/FileEntry/FileEntryActions.vue index 6804ee45e6..744ab69d55 100644 --- a/src/views/FilesList/FileEntry/FileEntryActions.vue +++ b/src/views/FilesList/FileEntry/FileEntryActions.vue @@ -29,16 +29,23 @@ + :can-close="!deleting" + :open.sync="confirmDelete"> {{ t('libresign', 'The signature request will be deleted. Do you confirm this action?') }} + + {{ t('libresign', 'Also delete the file.') }} + @@ -53,6 +60,7 @@ import svgTextBoxCheck from '@mdi/svg/svg/text-box-check.svg?raw' import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js' import NcActions from '@nextcloud/vue/dist/Components/NcActions.js' import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' +import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js' import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js' import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js' @@ -68,6 +76,7 @@ export default { NcActionButton, NcActions, NcButton, + NcCheckboxRadioSwitch, NcDialog, NcIconSvgWrapper, NcLoadingIcon, @@ -102,6 +111,8 @@ export default { return { enabledMenuActions: [], confirmDelete: false, + deleteFile: true, + deleting: false, } }, computed: { @@ -180,8 +191,10 @@ export default { registerAction(action) { this.enabledMenuActions = [...this.enabledMenuActions, action] }, - doDelete() { - this.filesStore.delete(this.source) + async doDelete() { + this.deleting = true + await this.filesStore.delete(this.source, this.deleteFile) + this.deleting = false }, }, }