Skip to content

Commit

Permalink
fix: Fix non-working RBACProvider on empty appName (#1900)
Browse files Browse the repository at this point in the history
This fixes the RBACProvider component: now, with the empty appName
property, it fetches permissions and update the state properly.
  • Loading branch information
gkarat authored Aug 29, 2023
1 parent a5e01d5 commit dca755e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/components/src/RBACProvider/RBACProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ const hasAccessWithUserPermissions = (userPermissions: (Access | string)[], chec
};

export interface RBACProviderProps {
appName: string;
checkResourceDefinitions: boolean;
appName?: string | null;
checkResourceDefinitions?: boolean;
}

export const RBACProvider: React.FunctionComponent<RBACProviderProps> = ({ appName, checkResourceDefinitions = false, children }) => {
const [permissionState, setPermissionState] = useState(initialPermissions);

const fetchPermissions = async () => {
const { isOrgAdmin, permissions: userPermissions } = await getRBAC(appName, true);
const { isOrgAdmin, permissions: userPermissions } = await getRBAC(appName === null ? '' : appName, true);

setPermissionState((currentPerms) => ({
...currentPerms,
Expand All @@ -38,8 +38,14 @@ export const RBACProvider: React.FunctionComponent<RBACProviderProps> = ({ appNa
};

useEffect(() => {
if (appName) {
// if null or string - then fetch the permissions
if (appName !== undefined) {
fetchPermissions();
} else {
setPermissionState((currentPerms) => ({
...currentPerms,
isLoading: false,
}));
}
}, [appName]);

Expand Down

0 comments on commit dca755e

Please sign in to comment.