1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

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.
This commit is contained in:
Nuno Góis 2024-01-24 08:20:38 +00:00 committed by GitHub
parent 68eb3dec07
commit 7413a1ee1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
}