From 345f87060b00705f7f3a18c30c7a5d311968fc62 Mon Sep 17 00:00:00 2001 From: Sergei Samokhvalov Date: Wed, 6 Nov 2024 16:03:02 +0300 Subject: [PATCH] Add getting patents --- .../new/collection/delete-collections.ts | 6 +----- .../check-and-set-collections-permission.ts | 18 ++++++++++-------- src/services/new/workbook/delete-workbooks.ts | 16 +++++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/services/new/collection/delete-collections.ts b/src/services/new/collection/delete-collections.ts index 7ff1b7e2..65b52798 100644 --- a/src/services/new/collection/delete-collections.ts +++ b/src/services/new/collection/delete-collections.ts @@ -33,11 +33,7 @@ export const deleteCollections = async ( ) => { const {collectionIds} = args; - const { - tenantId, - projectId, - // user: {userId}, - } = ctx.get('info'); + const {tenantId, projectId} = ctx.get('info'); ctx.log('DELETE_COLLECTIONS_START', { collectionIds: await Utils.macrotasksMap(collectionIds, (id) => Utils.encodeId(id)), diff --git a/src/services/new/collection/utils/check-and-set-collections-permission.ts b/src/services/new/collection/utils/check-and-set-collections-permission.ts index 66ffd13a..96b2b51b 100644 --- a/src/services/new/collection/utils/check-and-set-collections-permission.ts +++ b/src/services/new/collection/utils/check-and-set-collections-permission.ts @@ -33,6 +33,16 @@ export const checkAndSetCollectionPermission = async ( const targetTrx = getReplica(trx); let parentIds: string[] = []; + if (accessServiceEnabled) { + if (collectionInstance.model.parentId !== null) { + parentIds = await getParentIds({ + ctx, + trx: targetTrx, + collectionId: collectionInstance.model.parentId, + }); + } + } + if (accessServiceEnabled && !skipCheckPermissions && !isPrivateRoute) { let localPermission: CollectionPermission; @@ -44,14 +54,6 @@ export const checkAndSetCollectionPermission = async ( localPermission = CollectionPermission.View; } - if (collectionInstance.model.parentId !== null) { - parentIds = await getParentIds({ - ctx, - trx: targetTrx, - collectionId: collectionInstance.model.parentId, - }); - } - ctx.log('CHECK_PERMISSION', {permission: localPermission}); await collectionInstance.checkPermission({ diff --git a/src/services/new/workbook/delete-workbooks.ts b/src/services/new/workbook/delete-workbooks.ts index 6fdd25de..ffec8af6 100644 --- a/src/services/new/workbook/delete-workbooks.ts +++ b/src/services/new/workbook/delete-workbooks.ts @@ -60,6 +60,8 @@ export const deleteWorkbooks = async ( const workbooksMap: Map = new Map(); + let parentIds: string[] = []; + const checkDeletePermissionPromises = workbooks.map(async (workbook) => { if (workbook.model.isTemplate) { throw new AppError("Workbook template can't be deleted", { @@ -67,9 +69,7 @@ export const deleteWorkbooks = async ( }); } - if (accessServiceEnabled && !skipCheckPermissions) { - let parentIds: string[] = []; - + if (accessServiceEnabled) { if (workbook.model.collectionId !== null) { parentIds = await getParentIds({ ctx, @@ -80,10 +80,12 @@ export const deleteWorkbooks = async ( workbooksMap.set(workbook, parentIds); - await workbook.checkPermission({ - parentIds, - permission: WorkbookPermission.Delete, - }); + if (!skipCheckPermissions) { + await workbook.checkPermission({ + parentIds, + permission: WorkbookPermission.Delete, + }); + } } });