Skip to content

Commit

Permalink
feat: make possible delete file too
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Nov 5, 2024
1 parent 564be7d commit 3d571bf
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 9 deletions.
42 changes: 42 additions & 0 deletions lib/Controller/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Http::STATUS_OK, array{message: string}, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, array{message: string}, array{}>|DataResponse<Http::STATUS_UNPROCESSABLE_ENTITY, array{action: integer, errors: string[]}, array{}>
*
* 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
);
}
}
16 changes: 16 additions & 0 deletions lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
7 changes: 5 additions & 2 deletions src/store/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}))
}
Expand Down
27 changes: 20 additions & 7 deletions src/views/FilesList/FileEntry/FileEntryActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,23 @@
</NcActions>
<NcDialog v-if="confirmDelete"
:name="t('libresign', 'Confirm')"
@closing="confirmDelete = false">
:can-close="!deleting"
:open.sync="confirmDelete">
{{ t('libresign', 'The signature request will be deleted. Do you confirm this action?') }}
<NcCheckboxRadioSwitch :checked.sync="deleteFile" type="switch">
{{ t('libresign', 'Also delete the file.') }}
</NcCheckboxRadioSwitch>
<template #actions>
<NcButton type="error"
<NcButton type="primary"
@click="doDelete()">
{{ t('libresign', 'Yes') }}
<template #icon>
<NcLoadingIcon v-if="deleting" :size="20" />
</template>
{{ t('libresign', 'Ok') }}
</NcButton>
<NcButton type="primary"
<NcButton type="secondary"
@click="confirmDelete = false">
{{ t('libresign', 'No') }}
{{ t('libresign', 'Cancel') }}
</NcButton>
</template>
</NcDialog>
Expand All @@ -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'
Expand All @@ -68,6 +76,7 @@ export default {
NcActionButton,
NcActions,
NcButton,
NcCheckboxRadioSwitch,
NcDialog,
NcIconSvgWrapper,
NcLoadingIcon,
Expand Down Expand Up @@ -102,6 +111,8 @@ export default {
return {
enabledMenuActions: [],
confirmDelete: false,
deleteFile: true,
deleting: false,
}
},
computed: {
Expand Down Expand Up @@ -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
},
},
}
Expand Down

0 comments on commit 3d571bf

Please sign in to comment.