Skip to content

Commit 870b3cb

Browse files
remove all instances of update_user (#13198)
1 parent 9263baf commit 870b3cb

File tree

5 files changed

+19
-27
lines changed

5 files changed

+19
-27
lines changed

packages/manager/src/features/IAM/Users/UserDetails/UserEmailPanel.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('UserEmailPanel', () => {
108108
expect(errorText).toBeInTheDocument();
109109
});
110110

111-
it('disables the save button when the user does not have update_user permission', async () => {
111+
it('disables the save button when the user does not have is_account_admin permission', async () => {
112112
const user = accountUserFactory.build({
113113
email: 'my-linode-email',
114114
});

packages/manager/src/features/IAM/Users/UserDetails/UserProfile.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ import { UsernamePanel } from './UsernamePanel';
1919

2020
export const UserProfile = () => {
2121
const { username } = useParams({ from: '/iam/users/$username' });
22-
const { data: permissions } = usePermissions('account', [
23-
'is_account_admin',
24-
'update_user',
25-
'delete_user',
26-
]);
22+
const { data: permissions } = usePermissions('account', ['is_account_admin']);
2723

2824
const isAccountAdmin = permissions?.is_account_admin;
2925

@@ -34,10 +30,6 @@ export const UserProfile = () => {
3430
} = useAccountUser(username ?? '', isAccountAdmin);
3531
const { data: assignedRoles } = useUserRoles(username ?? '', isAccountAdmin);
3632

37-
// Only admin users get update_user and delete_user permissions, but doing a bit of defensive programming here to be safe.
38-
const canUpdateUser = isAccountAdmin || permissions?.update_user;
39-
const canDeleteUser = isAccountAdmin || permissions?.delete_user;
40-
4133
if (isLoading) {
4234
return <CircleProgress />;
4335
}
@@ -66,9 +58,9 @@ export const UserProfile = () => {
6658
sx={(theme) => ({ marginTop: theme.tokens.spacing.S16 })}
6759
>
6860
<UserDetailsPanel activeUser={user} assignedRoles={assignedRoles} />
69-
<UsernamePanel activeUser={user} canUpdateUser={canUpdateUser} />
70-
<UserEmailPanel activeUser={user} canUpdateUser={canUpdateUser} />
71-
<DeleteUserPanel activeUser={user} canDeleteUser={canDeleteUser} />
61+
<UsernamePanel activeUser={user} canUpdateUser={isAccountAdmin} />
62+
<UserEmailPanel activeUser={user} canUpdateUser={isAccountAdmin} />
63+
<DeleteUserPanel activeUser={user} canDeleteUser={isAccountAdmin} />
7264
</Stack>
7365
</>
7466
);

packages/manager/src/features/IAM/Users/UserDetails/UsernamePanel.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { UsernamePanel } from './UsernamePanel';
99
const queryMocks = vi.hoisted(() => ({
1010
userPermissions: vi.fn(() => ({
1111
data: {
12-
update_user: false,
12+
is_account_admin: false,
1313
},
1414
})),
1515
}));
@@ -31,7 +31,7 @@ describe('UsernamePanel', () => {
3131
expect(usernameTextField).toHaveDisplayValue(user.username);
3232
});
3333

34-
it('disables the input if the user doesn not have update_user permission', async () => {
34+
it('disables the input if the user doesn not have is_account_admin permission', async () => {
3535
const user = accountUserFactory.build();
3636

3737
const { getByLabelText } = renderWithTheme(
@@ -50,7 +50,7 @@ describe('UsernamePanel', () => {
5050
it("does not allow the user to update a proxy user's username", async () => {
5151
queryMocks.userPermissions.mockReturnValue({
5252
data: {
53-
update_user: true,
53+
is_account_admin: true,
5454
},
5555
});
5656

@@ -76,14 +76,14 @@ describe('UsernamePanel', () => {
7676
expect(getByText('Save').closest('button')).toBeDisabled();
7777
});
7878

79-
it('enables the save button when the user makes a change to the username and has update_user permission', async () => {
79+
it('enables the save button when the user makes a change to the username and has is_account_admin permission', async () => {
8080
const user = accountUserFactory.build({
8181
username: 'my-linode-username',
8282
});
8383

8484
queryMocks.userPermissions.mockReturnValue({
8585
data: {
86-
update_user: true,
86+
is_account_admin: true,
8787
},
8888
});
8989

@@ -102,14 +102,14 @@ describe('UsernamePanel', () => {
102102
expect(saveButton).toBeEnabled();
103103
});
104104

105-
it('disables the save button when the user does not have update_user permission', async () => {
105+
it('disables the save button when the user does not have is_account_admin permission', async () => {
106106
const user = accountUserFactory.build({
107107
username: 'my-linode-username',
108108
});
109109

110110
queryMocks.userPermissions.mockReturnValue({
111111
data: {
112-
update_user: false,
112+
is_account_admin: false,
113113
},
114114
});
115115

packages/manager/src/features/Profile/DisplaySettings/UsernameForm.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { UsernameForm } from './UsernameForm';
1111
const queryMocks = vi.hoisted(() => ({
1212
userPermissions: vi.fn(() => ({
1313
data: {
14-
update_user: false,
14+
is_account_admin: false,
1515
},
1616
})),
1717
}));
@@ -38,7 +38,7 @@ describe('UsernameForm', () => {
3838
await findByDisplayValue(profile.username);
3939
});
4040

41-
it('disables the input if the user doesn not have update_user permission', async () => {
41+
it('disables the input if the user doesn not have is_account_admin permission', async () => {
4242
const { getByLabelText } = renderWithTheme(<UsernameForm />);
4343

4444
expect(getByLabelText('Username')).toBeDisabled();
@@ -53,7 +53,7 @@ describe('UsernameForm', () => {
5353
it('disables the input if the user is a proxy user', async () => {
5454
queryMocks.userPermissions.mockReturnValue({
5555
data: {
56-
update_user: true,
56+
is_account_admin: true,
5757
},
5858
});
5959

@@ -73,14 +73,14 @@ describe('UsernameForm', () => {
7373
expect(getByLabelText('This field can’t be modified.')).toBeVisible();
7474
});
7575

76-
it('enables the save button when the user makes a change to the username and has update_user permission', async () => {
76+
it('enables the save button when the user makes a change to the username and has is_account_admin permission', async () => {
7777
const profile = profileFactory.build({ username: 'my-linode-username' });
7878

7979
server.use(http.get('*/v4/profile', () => HttpResponse.json(profile)));
8080

8181
queryMocks.userPermissions.mockReturnValue({
8282
data: {
83-
update_user: true,
83+
is_account_admin: true,
8484
},
8585
});
8686

packages/manager/src/features/Profile/DisplaySettings/UsernameForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const UsernameForm = () => {
2424

2525
const values = { username: profile?.username ?? '' };
2626

27-
const { data: permissions } = usePermissions('account', ['update_user']);
27+
const { data: permissions } = usePermissions('account', ['is_account_admin']);
2828

2929
const {
3030
control,
@@ -37,7 +37,7 @@ export const UsernameForm = () => {
3737
values,
3838
});
3939

40-
const tooltipForDisabledUsernameField = !permissions.update_user
40+
const tooltipForDisabledUsernameField = !permissions.is_account_admin
4141
? 'Restricted users cannot update their username. Please contact an account administrator.'
4242
: profile?.user_type === 'proxy'
4343
? RESTRICTED_FIELD_TOOLTIP

0 commit comments

Comments
 (0)