From 2a9d188c897cc783578c24769f3c48ac3b1df213 Mon Sep 17 00:00:00 2001 From: rajdip-b Date: Tue, 31 Dec 2024 11:19:24 +0530 Subject: [PATCH] simplified environment authority fetch --- apps/api/src/common/collective-authorities.ts | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/apps/api/src/common/collective-authorities.ts b/apps/api/src/common/collective-authorities.ts index 29990484..11e1801f 100644 --- a/apps/api/src/common/collective-authorities.ts +++ b/apps/api/src/common/collective-authorities.ts @@ -118,28 +118,17 @@ export const getCollectiveEnvironmentAuthorities = async ( workspaceMember: { userId, workspaceId: environment.project.workspaceId - } - }, - select: { + }, role: { - select: { - authorities: true - } - } - } - }) - - if (projectRoleAssociations.length === 0) { - return authorities - } - - const environmentRoleAssociations = - await prisma.projectWorkspaceRoleAssociation.findMany({ - where: { - projectId: environment.project.id, - environments: { - some: { - id: environment.id + projects: { + some: { + projectId: environment.project.id, + environments: { + some: { + id: environment.id + } + } + } } } }, @@ -158,11 +147,5 @@ export const getCollectiveEnvironmentAuthorities = async ( }) }) - environmentRoleAssociations.forEach((roleAssociation) => { - roleAssociation.role.authorities.forEach((authority) => { - authorities.add(authority) - }) - }) - return authorities }