Skip to content

Commit 855eabe

Browse files
fix: [UIE-9671] - IAM: create Linode permission fix (#13118)
* fix: [UIE-9671] - IAM: create Linode permission fix * fix: [UIE-9671] - test fix
1 parent 2f0bee0 commit 855eabe

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Fixed
3+
---
4+
5+
IAM: The StackScript/Linode selector is enabled in the Create Linode flow when the user doesn’t have the create_linode permission ([#13118](https://github.com/linode/manager/pull/13118))

packages/manager/src/features/Linodes/LinodeCreate/Actions.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ export const Actions = ({ isAlertsBetaMode }: ActionProps) => {
8383

8484
return (
8585
<Box sx={{ display: 'flex', gap: 1, justifyContent: 'flex-end' }}>
86-
<Button buttonType="outlined" onClick={onOpenAPIAwareness}>
86+
<Button
87+
buttonType="outlined"
88+
disabled={isDisabled}
89+
onClick={onOpenAPIAwareness}
90+
>
8791
View Code Snippets
8892
</Button>
8993
<Button

packages/manager/src/features/Linodes/LinodeCreate/Tabs/StackScripts/StackScriptSelectionRow.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/* eslint-disable jsx-a11y/label-has-associated-control */
22
import { Radio, Stack, Typography } from '@linode/ui';
33
import { truncate } from '@linode/utilities';
4+
import { useLocation } from '@tanstack/react-router';
45
import React from 'react';
56

67
import { InlineMenuAction } from 'src/components/InlineMenuAction/InlineMenuAction';
78
import { TableCell } from 'src/components/TableCell';
89
import { TableRow } from 'src/components/TableRow';
10+
import { usePermissions } from 'src/features/IAM/hooks/usePermissions';
911
import { isLKEStackScript } from 'src/features/StackScripts/stackScriptUtils';
1012

1113
import type { StackScript } from '@linode/api-v4';
@@ -21,6 +23,13 @@ interface Props {
2123
export const StackScriptSelectionRow = (props: Props) => {
2224
const { disabled, isSelected, onOpenDetails, onSelect, stackscript } = props;
2325

26+
const location = useLocation();
27+
const { data: permissions } = usePermissions('account', ['create_linode']);
28+
29+
const rowIsDisabled =
30+
disabled ||
31+
(!permissions?.create_linode &&
32+
location.pathname.includes('/linodes/create'));
2433
// Never show LKE StackScripts. We try to hide these from the user even though they
2534
// are returned by the API.
2635
if (isLKEStackScript(stackscript)) {
@@ -32,7 +41,7 @@ export const StackScriptSelectionRow = (props: Props) => {
3241
<TableCell>
3342
<Radio
3443
checked={isSelected}
35-
disabled={disabled}
44+
disabled={rowIsDisabled}
3645
id={`stackscript-${stackscript.id}`}
3746
onChange={onSelect}
3847
/>
@@ -61,7 +70,11 @@ export const StackScriptSelectionRow = (props: Props) => {
6170
</label>
6271
</TableCell>
6372
<TableCell actionCell>
64-
<InlineMenuAction actionText="Show Details" onClick={onOpenDetails} />
73+
<InlineMenuAction
74+
actionText="Show Details"
75+
disabled={rowIsDisabled}
76+
onClick={onOpenDetails}
77+
/>
6578
</TableCell>
6679
</TableRow>
6780
);

packages/manager/src/features/Linodes/LinodeCreate/shared/LinodeSelectTable.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const queryMocks = vi.hoisted(() => ({
2020
userPermissions: vi.fn(() => ({
2121
data: {
2222
clone_linode: true,
23+
create_linode: true,
2324
},
2425
})),
2526
}));

packages/manager/src/features/Linodes/LinodeCreate/shared/LinodeSelectTableRow.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const queryMocks = vi.hoisted(() => ({
1717
data: {
1818
shutdown_linode: false,
1919
clone_linode: false,
20+
create_linode: false,
2021
},
2122
})),
2223
}));
@@ -71,6 +72,7 @@ describe('LinodeSelectTableRow', () => {
7172
data: {
7273
shutdown_linode: false,
7374
clone_linode: true,
75+
create_linode: true,
7476
},
7577
});
7678
const linode = linodeFactory.build();
@@ -182,6 +184,7 @@ describe('LinodeSelectTableRow', () => {
182184
data: {
183185
shutdown_linode: true,
184186
clone_linode: true,
187+
create_linode: true,
185188
},
186189
});
187190

packages/manager/src/features/Linodes/LinodeCreate/shared/LinodeSelectTableRow.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export const LinodeSelectTableRow = (props: Props) => {
3333

3434
const region = regions?.find((r) => r.id === linode.region);
3535

36+
const { data: accountPermissions } = usePermissions('account', [
37+
'create_linode',
38+
]);
39+
3640
const { data: permissions } = usePermissions(
3741
'linode',
3842
['shutdown_linode', 'clone_linode'],
@@ -45,7 +49,9 @@ export const LinodeSelectTableRow = (props: Props) => {
4549
<FormControlLabel
4650
checked={selected}
4751
control={<Radio />}
48-
disabled={!permissions.clone_linode}
52+
disabled={
53+
!permissions.clone_linode || !accountPermissions?.create_linode
54+
}
4955
label={linode.label}
5056
onChange={onSelect}
5157
sx={{ gap: 2 }}

0 commit comments

Comments
 (0)