From d35cd21f0665f246a3ae34850b066ac1bd580bb6 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Thu, 28 Dec 2023 23:28:55 +0600 Subject: [PATCH] UBERF-4784 (#4286) Signed-off-by: Denis Bykhov --- .../src/components/DeleteConfirmationPopup.svelte | 2 ++ plugins/view-resources/src/actionImpl.ts | 12 ++++++++++-- plugins/view-resources/src/utils.ts | 8 +++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte b/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte index 42c8aebc48..f546d182af 100644 --- a/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte +++ b/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte @@ -26,6 +26,7 @@ export let object: Doc | Doc[] export let deleteAction: () => void + export let skipCheck: boolean = false const objectArray = Array.isArray(object) ? object : [object] const owners: PersonAccount[] = Array.from($personAccountByIdStore.values()).filter( (acc) => acc.role === AccountRole.Owner @@ -33,6 +34,7 @@ const dispatch = createEventDispatcher() $: creators = [...new Set(objectArray.map((obj) => obj.createdBy as Ref))] $: canDelete = + skipCheck || (creators.length === 1 && creators.includes(getCurrentAccount()._id as Ref)) || getCurrentAccount().role === AccountRole.Owner $: label = canDelete ? view.string.DeleteObject : view.string.DeletePopupNoPermissionTitle diff --git a/plugins/view-resources/src/actionImpl.ts b/plugins/view-resources/src/actionImpl.ts index 951e578d1e..f473645db5 100644 --- a/plugins/view-resources/src/actionImpl.ts +++ b/plugins/view-resources/src/actionImpl.ts @@ -73,14 +73,22 @@ async function CopyTextToClipboard ( } } -function Delete (object: Doc | Doc[]): void { +function Delete ( + object: Doc | Doc[], + evt: Event, + props: { + skipCheck: boolean + } +): void { + const skipCheck = props?.skipCheck ?? false showPopup( contact.component.DeleteConfirmationPopup, { object, + skipCheck, deleteAction: async () => { const objs = Array.isArray(object) ? object : [object] - await deleteObjects(getClient(), objs).catch((err) => { + await deleteObjects(getClient(), objs, skipCheck).catch((err) => { console.error(err) }) } diff --git a/plugins/view-resources/src/utils.ts b/plugins/view-resources/src/utils.ts index 1d64fb87e1..19ef424020 100644 --- a/plugins/view-resources/src/utils.ts +++ b/plugins/view-resources/src/utils.ts @@ -359,9 +359,11 @@ export async function deleteObject (client: TxOperations, object: Doc): Promise< } } -export async function deleteObjects (client: TxOperations, objects: Doc[]): Promise { - const currentAcc = getCurrentAccount() - if (currentAcc.role !== AccountRole.Owner && objects.some((p) => p.createdBy !== currentAcc._id)) return +export async function deleteObjects (client: TxOperations, objects: Doc[], skipCheck: boolean = false): Promise { + if (!skipCheck) { + const currentAcc = getCurrentAccount() + if (currentAcc.role !== AccountRole.Owner && objects.some((p) => p.createdBy !== currentAcc._id)) return + } const ops = client.apply('delete') for (const object of objects) { if (client.getHierarchy().isDerived(object._class, core.class.AttachedDoc)) {