Skip to content

Commit

Permalink
Add new Check in the useIsResourceRestricted logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hasyed-akamai committed Oct 14, 2024
1 parent 032a6c0 commit 5748b02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
15 changes: 6 additions & 9 deletions packages/manager/src/features/VPCs/VPCLanding/VPCRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TableCell } from 'src/components/TableCell';
import { TableRow } from 'src/components/TableRow';
import { useRegionsQuery } from 'src/queries/regions/regions';
import { getRestrictedResourceText } from 'src/features/Account/utils';
import { useGrants } from 'src/queries/profile/profile';
import { useIsResourceRestricted } from 'src/hooks/useIsResourceRestricted';

interface Props {
handleDeleteVPC: () => void;
Expand All @@ -27,14 +27,11 @@ export const VPCRow = ({ handleDeleteVPC, handleEditVPC, vpc }: Props) => {
0
);

const { data: grants } = useGrants();

const isVPCReadOnly =
grants &&
(grants['vpc'].some(
(grant) => grant.id === vpc.id && grant.permissions === 'read_only'
) ||
!grants['vpc'].some((grant) => grant.id === vpc.id));
const isVPCReadOnly = useIsResourceRestricted({
grantLevel: 'read_only',
grantType: 'vpc',
id: vpc.id,
});

const actions: Action[] = [
{
Expand Down
6 changes: 4 additions & 2 deletions packages/manager/src/hooks/useIsResourceRestricted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const useIsResourceRestricted = ({
if (!grants) {
return false;
}
return grants[grantType].some(
(grant) => grant.id === id && grant.permissions === grantLevel
return (
grants[grantType].some(
(grant) => grant.id === id && grant.permissions === grantLevel
) || !grants[grantType].some((grant) => grant.id === id)
);
};

0 comments on commit 5748b02

Please sign in to comment.