From 034f2c309b7893cb4449f210df5bb02e37cf98f8 Mon Sep 17 00:00:00 2001 From: "Misha M.-Kupriyanov" Date: Tue, 6 Aug 2024 11:56:43 +0200 Subject: [PATCH] feat(files_sharing): confirm share deletion in order to prevent accidental share deletion Signed-off-by: Misha M.-Kupriyanov --- apps/files_sharing/src/mixins/SharesMixin.js | 41 +++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/apps/files_sharing/src/mixins/SharesMixin.js b/apps/files_sharing/src/mixins/SharesMixin.js index 994a0fe5cb319..9f9b487a1891d 100644 --- a/apps/files_sharing/src/mixins/SharesMixin.js +++ b/apps/files_sharing/src/mixins/SharesMixin.js @@ -5,7 +5,7 @@ import { emit } from '@nextcloud/event-bus' import { fetchNode } from '../services/WebdavClient.ts' -import { showError, showSuccess } from '@nextcloud/dialogs' +import { DialogBuilder, showError, showSuccess } from '@nextcloud/dialogs' import { getCurrentUser } from '@nextcloud/auth' // eslint-disable-next-line import/no-unresolved, n/no-missing-import import PQueue from 'p-queue' @@ -253,10 +253,49 @@ export default { } }, + /** + * Display delete share confirmation dialog + * @returns {Promise} + */ + async askDeleteConfirmation() { + let confirmed = false + const message = this.share.itemType === 'file' + ? t('files_sharing', 'File "{path}" will be unshared', { path: this.share.path }) + : t('files_sharing', 'Folder "{path}" will be unshared', { path: this.share.path }) + + await new DialogBuilder() + .setName(t('files_sharing', 'Delete share')) + .setText(t('files_sharing', message)) + .setButtons([ + { + label: t('core', 'Cancel'), + }, + { + label: t('files_sharing', 'Delete share'), + type: 'error', + callback: () => { + confirmed = true + }, + }, + ]) + .build() + .show() + + return confirmed + }, /** * Delete share button handler */ async onDelete() { + console.debug('Deleting share', this.share.id) + this.open = false + const deletionConfirmed = await this.askDeleteConfirmation() + + if (!deletionConfirmed) { + console.debug('Deletion aborted', this.share.id) + return + } + try { this.loading = true this.open = false