Skip to content

Commit

Permalink
feat(files_sharing): confirm share deletion
Browse files Browse the repository at this point in the history
in order to prevent accidental share deletion

Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
  • Loading branch information
printminion-co committed Sep 24, 2024
1 parent e247c26 commit 034f2c3
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion apps/files_sharing/src/mixins/SharesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -253,10 +253,49 @@ export default {
}
},

/**
* Display delete share confirmation dialog
* @returns {Promise<boolean>}
*/
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
Expand Down

0 comments on commit 034f2c3

Please sign in to comment.