Skip to content

Commit

Permalink
chore: add support for project and environment in PermissionGuard (#6008
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
nunogois committed Jan 24, 2024
1 parent 68eb3de commit 7413a1e
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -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);
Expand All @@ -26,7 +30,7 @@ export const PermissionGuard = ({
permissionsArray.push(ADMIN);
}

if (hasAccess(permissionsArray)) {
if (hasAccess(permissionsArray, project, environment)) {
return children;
}

Expand Down

0 comments on commit 7413a1e

Please sign in to comment.