UBERF-4784 (#4286)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-12-28 23:28:55 +06:00 committed by GitHub
parent 682e7745e7
commit d35cd21f06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

@ -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

View File

@ -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)
})
}

View File

@ -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)) {