Repository navigation
feat: [UIE-9341, UIE-9342, UIE-9521] - IAM: fix perm for vpcs #13050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f852163
97c2f21
fbf60fe
f8375c4
f0aaafe
7e76469
b529b42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@linode/manager": Changed | ||
| --- | ||
|
|
||
| IAM: fix permissiom's check for vpc for assigning/unassigning linodes ([#13050](https://github.com/linode/manager/pull/13050)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,10 +15,7 @@ | |
|
|
||
| import { DownloadCSV } from 'src/components/DownloadCSV/DownloadCSV'; | ||
| import { RemovableSelectionsListTable } from 'src/components/RemovableSelectionsList/RemovableSelectionsListTable'; | ||
| import { | ||
| usePermissions, | ||
| useQueryWithPermissions, | ||
| } from 'src/features/IAM/hooks/usePermissions'; | ||
| import { useQueryWithPermissions } from 'src/features/IAM/hooks/usePermissions'; | ||
| import { REMOVABLE_SELECTIONS_LINODES_TABLE_HEADERS } from 'src/features/VPCs/constants'; | ||
| import { useUnassignLinode } from 'src/hooks/useUnassignLinode'; | ||
| import { useVPCDualStack } from 'src/hooks/useVPCDualStack'; | ||
|
|
@@ -97,47 +94,37 @@ | |
|
|
||
| const hasError = React.useRef(false); // This flag is used to prevent the drawer from closing if an error occurs. | ||
|
|
||
| const [linodeOptionsToUnassign, setLinodeOptionsToUnassign] = | ||
| React.useState<Linode[]>([]); | ||
| const [interfacesToDelete, setInterfacesToDelete] = React.useState< | ||
| DeleteInterfaceIds[] | ||
| >([]); | ||
|
|
||
| const { linodes: subnetLinodeIds } = subnet || {}; | ||
|
|
||
| // 1. We need to get all the linodes. | ||
| // TODO: change to 'delete_linode_config_profile_interface' once it's available | ||
|
Check warning on line 104 in packages/manager/src/features/VPCs/VPCDetail/SubnetUnassignLinodesDrawer.tsx
|
||
| const { | ||
| data: linodes, | ||
| data: filteredLinodes, | ||
| error: linodesError, | ||
| isLoading: isLoadingFilteredLinodes, | ||
| refetch: getCSVData, | ||
| } = useAllLinodesQuery(); | ||
| } = useQueryWithPermissions<Linode>( | ||
| useAllLinodesQuery({}, {}, open), | ||
| 'linode', | ||
| ['delete_linode'], | ||
| open | ||
| ); | ||
| const userCanUnassignLinodes = filteredLinodes?.length > 0; | ||
|
|
||
| // 2. We need to filter only the linodes that are assigned to the subnet. | ||
| const findAssignedLinodes = React.useCallback(() => { | ||
| return linodes?.filter((linode) => { | ||
| const linodeOptionsToUnassign = React.useMemo(() => { | ||
| // 2. We need to filter only the linodes that are assigned to the subnet. | ||
| if (!filteredLinodes) return []; | ||
|
|
||
| return filteredLinodes?.filter((linode) => { | ||
| return subnetLinodeIds?.some( | ||
| (linodeInfo) => linodeInfo.id === linode.id | ||
| ); | ||
| }); | ||
| }, [linodes, subnetLinodeIds]); | ||
|
|
||
| const { data: permissions } = usePermissions('vpc', ['update_vpc'], vpcId); | ||
| // TODO: change to 'delete_linode_config_profile_interface' once it's available | ||
| const { data: filteredLinodes, isLoading: isLoadingFilteredLinodes } = | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the issue that we didn't see filtered linodes by permission on the autocomplete because we didn't use |
||
| useQueryWithPermissions<Linode>( | ||
| useAllLinodesQuery({}, {}, open), | ||
| 'linode', | ||
| ['delete_linode'], | ||
| open | ||
| ); | ||
| const userCanUnassignLinodes = | ||
| permissions.update_vpc && filteredLinodes?.length > 0; | ||
|
|
||
| React.useEffect(() => { | ||
| if (linodes) { | ||
| setLinodeOptionsToUnassign(findAssignedLinodes() ?? []); | ||
| } | ||
| }, [linodes, setLinodeOptionsToUnassign, findAssignedLinodes]); | ||
| }, [subnetLinodeIds, filteredLinodes]); | ||
|
|
||
| // 3. When a linode is selected, we need to get the VPC interface to unassign. | ||
| const getVPCInterface = React.useCallback( | ||
|
|
@@ -340,12 +327,6 @@ | |
| subnet?.ipv4 ?? subnet?.ipv6 ?? 'Unknown' | ||
| })`} | ||
| > | ||
| {!userCanUnassignLinodes && linodeOptionsToUnassign.length > 0 && ( | ||
| <Notice | ||
| text={`You don't have permissions to unassign Linodes from ${subnet?.label}. Please contact an account administrator for details.`} | ||
| variant="error" | ||
| /> | ||
| )} | ||
| {unassignLinodesErrors.length > 0 && ( | ||
| <Notice text={unassignLinodesErrors[0].reason} variant="error" /> | ||
| )} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaleksee-akamai because of deferring the getLinodes call to when the drawer is open we have to adjust the test accordingly. All good here π