From 25bc8196706293f1ecc1199eb4f559645690fe05 Mon Sep 17 00:00:00 2001 From: Alexandr Yushkov Date: Fri, 8 Dec 2023 15:31:27 +0100 Subject: [PATCH] Lift the tenant check for mirrored entries (#38) --- src/services/new/collection/utils/get-parents.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/services/new/collection/utils/get-parents.ts b/src/services/new/collection/utils/get-parents.ts index ce3cf322..17aa3d9a 100644 --- a/src/services/new/collection/utils/get-parents.ts +++ b/src/services/new/collection/utils/get-parents.ts @@ -17,7 +17,7 @@ interface GetCollectionParentIds extends Ctx { } export const getParents = async ({ctx, trx, collectionIds}: GetCollectionsParentIds) => { - const {tenantId, projectId} = ctx.get('info'); + const {tenantId, projectId, onlyMirrored} = ctx.get('info'); const targetTrx = getReplica(trx); @@ -28,7 +28,7 @@ export const getParents = async ({ctx, trx, collectionIds}: GetCollectionsParent qb1.select() .from(CollectionModel.tableName) .where({ - [CollectionModelColumn.TenantId]: tenantId, + ...(onlyMirrored ? {} : {[CollectionModelColumn.TenantId]: tenantId}), [CollectionModelColumn.ProjectId]: projectId, [CollectionModelColumn.DeletedAt]: null, }) @@ -37,8 +37,12 @@ export const getParents = async ({ctx, trx, collectionIds}: GetCollectionsParent qb2.select(`${CollectionModel.tableName}.*`) .from(CollectionModel.tableName) .where({ - [`${CollectionModel.tableName}.${CollectionModelColumn.TenantId}`]: - tenantId, + ...(onlyMirrored + ? {} + : { + [`${CollectionModel.tableName}.${CollectionModelColumn.TenantId}`]: + tenantId, + }), [`${CollectionModel.tableName}.${CollectionModelColumn.ProjectId}`]: projectId, [`${CollectionModel.tableName}.${CollectionModelColumn.DeletedAt}`]: