From 7413a1ee1a88579ec322cc02bfeeda105643c8fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Wed, 24 Jan 2024 08:20:38 +0000 Subject: [PATCH] chore: add support for project and environment in PermissionGuard (#6008) I noticed some manual `hasAccess` usages in permission guards due to the fact that `PermissionGuard` does not accept `project` and `environment`. This PR adds this support to `PermissionGuard` so we can adapt these `hasAccess` checks to use it instead, adding consistency and cleaning things up. This PR does not include these adaptations however, it only adds the optional properties to the component. We can address these at a later point. --- .../component/common/PermissionGuard/PermissionGuard.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/component/common/PermissionGuard/PermissionGuard.tsx b/frontend/src/component/common/PermissionGuard/PermissionGuard.tsx index d95dff4ed8..9c83578f23 100644 --- a/frontend/src/component/common/PermissionGuard/PermissionGuard.tsx +++ b/frontend/src/component/common/PermissionGuard/PermissionGuard.tsx @@ -9,11 +9,15 @@ const StyledList = styled('ul')(({ theme }) => ({ interface IPermissionGuardProps { permissions: string | string[]; + project?: string; + environment?: string; children: JSX.Element; } export const PermissionGuard = ({ permissions, + project, + environment, children, }: IPermissionGuardProps) => { const { hasAccess } = useContext(AccessContext); @@ -26,7 +30,7 @@ export const PermissionGuard = ({ permissionsArray.push(ADMIN); } - if (hasAccess(permissionsArray)) { + if (hasAccess(permissionsArray, project, environment)) { return children; }