Skip to content

Commit

Permalink
Fix deleteWorkbooks for non-Zitadel mode
Browse files Browse the repository at this point in the history
  • Loading branch information
imsitnikov committed Dec 12, 2024
1 parent ad57c9d commit 31beed6
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/services/new/workbook/delete-workbooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,31 @@ export const deleteWorkbooks = async (

const workbooksMap: Map<WorkbookInstance, string[]> = new Map();

let parentIds: string[] = [];

const checkDeletePermissionPromises = workbooks.map(async (workbook) => {
if (workbook.model.isTemplate) {
throw new AppError("Workbook template can't be deleted", {
code: US_ERRORS.WORKBOOK_TEMPLATE_CANT_BE_DELETED,
});
}

if (accessServiceEnabled) {
if (workbook.model.collectionId !== null) {
parentIds = await getParentIds({
ctx,
trx: targetTrx,
collectionId: workbook.model.collectionId,
});
}
let parentIds: string[] = [];

workbooksMap.set(workbook, parentIds);
if (workbook.model.collectionId !== null) {
parentIds = await getParentIds({
ctx,
trx: targetTrx,
collectionId: workbook.model.collectionId,
});
}

if (!skipCheckPermissions) {
await workbook.checkPermission({
parentIds,
permission: WorkbookPermission.Delete,
});
}
if (accessServiceEnabled && !skipCheckPermissions) {
await workbook.checkPermission({
parentIds,
permission: WorkbookPermission.Delete,
});
}

workbooksMap.set(workbook, parentIds);
});

await Promise.all(checkDeletePermissionPromises);
Expand Down

0 comments on commit 31beed6

Please sign in to comment.