Skip to content

Commit 1c4902e

Browse files
feat: [UIE-9392] - IAM Delegation: permissions check for Parent Account (linode#13063)
Co-authored-by: Alban Bailly <abailly@akamai.com>
1 parent 7eb591a commit 1c4902e

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Upcoming Features
3+
---
4+
5+
IAM Parent/Child: delegate permissions for parent account ([#13063](https://github.com/linode/manager/pull/13063))

packages/manager/src/features/IAM/Delegations/AccountDelegationsTableRow.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { InlineMenuAction } from 'src/components/InlineMenuAction/InlineMenuActi
55
import { TableCell } from 'src/components/TableCell';
66
import { TableRow } from 'src/components/TableRow/TableRow';
77

8+
import { usePermissions } from '../hooks/usePermissions';
89
import { TruncatedList } from '../Shared/TruncatedList';
910
import { UpdateDelegationsDrawer } from './UpdateDelegationsDrawer';
1011

@@ -19,6 +20,9 @@ export const AccountDelegationsTableRow = ({ delegation, index }: Props) => {
1920
const theme = useTheme();
2021
const [isDrawerOpen, setIsDrawerOpen] = React.useState(false);
2122

23+
const { data: permissions } = usePermissions('account', [
24+
'update_delegate_users',
25+
]);
2226
const handleUpdateDelegations = () => {
2327
setIsDrawerOpen(true);
2428
};
@@ -118,11 +122,17 @@ export const AccountDelegationsTableRow = ({ delegation, index }: Props) => {
118122
</Typography>
119123
)}
120124
</TableCell>
121-
<TableCell sx={{ textAlign: 'right', whiteSpace: 'nowrap' }}>
125+
<TableCell sx={{ textAlign: 'right', whiteSpace: 'nowrap', pr: 0 }}>
122126
<InlineMenuAction
123127
actionText="Update Delegations"
124128
buttonHeight={40}
129+
disabled={!permissions.update_delegate_users}
125130
onClick={handleUpdateDelegations}
131+
tooltip={
132+
!permissions.update_delegate_users
133+
? 'You do not have permission to update delegations.'
134+
: undefined
135+
}
126136
/>
127137
</TableCell>
128138
<UpdateDelegationsDrawer

packages/manager/src/features/IAM/Delegations/UpdateDelegationsDrawer.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { enqueueSnackbar } from 'notistack';
1414
import React from 'react';
1515
import { Controller, FormProvider, useForm } from 'react-hook-form';
1616

17+
import { usePermissions } from '../hooks/usePermissions';
1718
import {
1819
DELEGATION_VALIDATION_ERROR,
1920
INTERNAL_ERROR_NO_CHANGES_SAVED,
@@ -50,6 +51,10 @@ export const UpdateDelegationsDrawer = ({
5051
filters: { user_type: 'parent' },
5152
});
5253

54+
const { data: permissions } = usePermissions('account', [
55+
'update_delegate_users',
56+
]);
57+
5358
const { mutateAsync: updateDelegates } =
5459
useUpdateChildAccountDelegatesQuery();
5560

@@ -180,6 +185,10 @@ export const UpdateDelegationsDrawer = ({
180185
label: 'Update',
181186
loading: isSubmitting,
182187
type: 'submit',
188+
disabled: !permissions?.update_delegate_users,
189+
tooltipText: !permissions?.update_delegate_users
190+
? 'You do not have permission to update delegations.'
191+
: undefined,
183192
}}
184193
secondaryButtonProps={{
185194
'data-testid': 'cancel',

packages/manager/src/routes/IAM/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ const iamDelegationsRoute = createRoute({
138138
path: 'delegations',
139139
beforeLoad: async ({ context }) => {
140140
const isDelegationEnabled = context?.flags?.iamDelegation?.enabled;
141-
if (!isDelegationEnabled) {
141+
const profile = context?.profile;
142+
143+
const isChildAccount = profile?.user_type === 'child';
144+
if (!isDelegationEnabled || isChildAccount) {
142145
throw redirect({
143146
to: '/iam/users',
144147
});

0 commit comments

Comments
 (0)