Skip to content

Commit

Permalink
fix: Fix usage of null values in RBAC RDs
Browse files Browse the repository at this point in the history
Make sure null values are not left out when RBAC RD value is an array.
  • Loading branch information
gkarat committed Aug 14, 2023
1 parent a7976ed commit cf06665
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/components/src/RBACProvider/RBACProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
} from '@redhat-cloud-services/frontend-components-utilities/RBAC';

const hasAccessWithUserPermissions = (userPermissions: (Access | string)[], checkResourceDefinitions: boolean) => {
return (requiredPermissions: (Access | string)[], checkAll?: boolean): boolean => {
return (requiredPermissions: (Access | string)[], checkAll?: boolean, checkResourceDefinitionsOverride?: boolean): boolean => {
return checkAll
? hasAllPermissions(userPermissions, requiredPermissions, checkResourceDefinitions)
: doesHavePermissions(userPermissions, requiredPermissions, checkResourceDefinitions);
? hasAllPermissions(userPermissions, requiredPermissions, checkResourceDefinitionsOverride ?? checkResourceDefinitions)
: doesHavePermissions(userPermissions, requiredPermissions, checkResourceDefinitionsOverride ?? checkResourceDefinitions);
};
};

Expand Down
5 changes: 2 additions & 3 deletions packages/utils/src/RBAC/RBAC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ function extractResourceDefinitionValues(rds: ResourceDefinition[]) {
if (operation === ResourceDefinitionFilterOperationEnum.In) {
return [
...acc,
...value
.toString()
...(Array.isArray(value) ? value.map((value) => (value === null ? 'null' : value)).toString() : value)
.split(',')
.map((value) => `${key}:${value}`),
];
Expand Down Expand Up @@ -135,7 +134,7 @@ export interface UsePermissionsContextState {
isLoading?: boolean;
isOrgAdmin: boolean;
permissions: (string | Access)[];
hasAccess?: (requiredPermissions: (Access | string)[], checkAll?: boolean) => boolean;
hasAccess?: (requiredPermissions: (Access | string)[], checkAll?: boolean, checkResourceDefinitionsOverride?: boolean) => boolean;
}

export const initialPermissions: UsePermissionsContextState = {
Expand Down
8 changes: 6 additions & 2 deletions packages/utils/src/RBACHook/RBACHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ export function usePermissions(
return permissions;
}

export const usePermissionsWithContext = (requiredPermissions: (Access | string)[], checkAll?: boolean) => {
export const usePermissionsWithContext = (
requiredPermissions: (Access | string)[],
checkAll?: boolean,
checkResourceDefinitionsOverride?: boolean
) => {
const { hasAccess, ...permissionState } = useContext(RBACContext);

return {
...permissionState,
hasAccess: hasAccess?.(requiredPermissions, checkAll) || false,
hasAccess: hasAccess?.(requiredPermissions, checkAll, checkResourceDefinitionsOverride) || false,
};
};

Expand Down

0 comments on commit cf06665

Please sign in to comment.