mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-13 03:40:48 +00:00
UBERF-4784 (#4286)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
682e7745e7
commit
d35cd21f06
@ -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<PersonAccount>))]
|
||||
$: canDelete =
|
||||
skipCheck ||
|
||||
(creators.length === 1 && creators.includes(getCurrentAccount()._id as Ref<PersonAccount>)) ||
|
||||
getCurrentAccount().role === AccountRole.Owner
|
||||
$: label = canDelete ? view.string.DeleteObject : view.string.DeletePopupNoPermissionTitle
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
@ -359,9 +359,11 @@ export async function deleteObject (client: TxOperations, object: Doc): Promise<
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteObjects (client: TxOperations, objects: Doc[]): Promise<void> {
|
||||
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<void> {
|
||||
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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user