Skip to content

Commit cf16ee0

Browse files
chore: Remove useAccountManagement hook and fix some restricted user UI (#12223)
* initial clean up * clean up unnessesary notices * clean up * add safety to grants fetch to fix e2e * Revert "add safety to grants fetch to fix e2e" This reverts commit 5b6a537. * fix up cypress tests * remove check for longview landing notice * fix cypress test * remove `add_buckets` grant because it does not exist? * fix * Added changeset: `add_buckets` from `GlobalGrantTypes` * Added changeset: Inconsistent restricted user notices on landing pages * Added changeset: Remove `useAccountManagement` hook --------- Co-authored-by: Banks Nussman <[email protected]>
1 parent e54e893 commit cf16ee0

39 files changed

+401
-472
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/api-v4": Removed
3+
---
4+
5+
`add_buckets` from `GlobalGrantTypes` ([#12223](https://github.com/linode/manager/pull/12223))

packages/api-v4/src/account/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ export interface Grant {
199199
}
200200
export type GlobalGrantTypes =
201201
| 'account_access'
202-
| 'add_buckets'
203202
| 'add_databases'
204203
| 'add_domains'
205204
| 'add_firewalls'
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+
Inconsistent restricted user notices on landing pages ([#12223](https://github.com/linode/manager/pull/12223))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Tech Stories
3+
---
4+
5+
Remove `useAccountManagement` hook ([#12223](https://github.com/linode/manager/pull/12223))

packages/manager/cypress/e2e/core/account/account-cancellation.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file Integration tests for Cloud Manager account cancellation flows.
33
*/
44

5-
import { profileFactory } from '@linode/utilities';
5+
import { grantsFactory, profileFactory } from '@linode/utilities';
66
import {
77
cancellationDataLossWarning,
88
cancellationDialogTitle,
@@ -14,7 +14,10 @@ import {
1414
mockGetAccount,
1515
} from 'support/intercepts/account';
1616
import { mockWebpageUrl } from 'support/intercepts/general';
17-
import { mockGetProfile } from 'support/intercepts/profile';
17+
import {
18+
mockGetProfile,
19+
mockGetProfileGrants,
20+
} from 'support/intercepts/profile';
1821
import { ui } from 'support/ui';
1922
import {
2023
randomDomainName,
@@ -170,14 +173,16 @@ describe('Account cancellation', () => {
170173
171174
restricted: true,
172175
});
176+
const mockGrants = grantsFactory.build();
173177

174178
mockGetAccount(mockAccount).as('getAccount');
175179
mockGetProfile(mockProfile).as('getProfile');
180+
mockGetProfileGrants(mockGrants).as('getGrants');
176181
mockCancelAccountError('Unauthorized', 403).as('cancelAccount');
177182

178183
// Navigate to Account Settings page, click "Close Account" button.
179184
cy.visitWithLogin('/account/settings');
180-
cy.wait(['@getAccount', '@getProfile']);
185+
cy.wait(['@getAccount', '@getProfile', '@getGrants']);
181186

182187
cy.findByTestId('close-account')
183188
.should('be.visible')

packages/manager/cypress/e2e/core/account/account-linode-managed.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
* @file Integration tests for Cloud Manager account enable Linode Managed flows.
33
*/
44

5-
import { linodeFactory, profileFactory } from '@linode/utilities';
5+
import {
6+
grantsFactory,
7+
linodeFactory,
8+
profileFactory,
9+
} from '@linode/utilities';
610
import {
711
visitUrlWithManagedDisabled,
812
visitUrlWithManagedEnabled,
@@ -17,7 +21,10 @@ import {
1721
mockGetAccount,
1822
} from 'support/intercepts/account';
1923
import { mockGetLinodes } from 'support/intercepts/linodes';
20-
import { mockGetProfile } from 'support/intercepts/profile';
24+
import {
25+
mockGetProfile,
26+
mockGetProfileGrants,
27+
} from 'support/intercepts/profile';
2128
import { ui } from 'support/ui';
2229
import { chooseRegion } from 'support/util/regions';
2330

@@ -100,16 +107,18 @@ describe('Account Linode Managed', () => {
100107
restricted: true,
101108
username: 'mock-restricted-user',
102109
});
110+
const mockGrants = grantsFactory.build();
103111
const errorMessage = 'Unauthorized';
104112

105113
mockGetLinodes([]);
106114
mockGetAccount(mockAccount).as('getAccount');
107115
mockGetProfile(mockProfile).as('getProfile');
116+
mockGetProfileGrants(mockGrants).as('getGrants');
108117
mockEnableLinodeManagedError(errorMessage, 403).as('enableLinodeManaged');
109118

110119
// Navigate to Account Settings page, click "Add Linode Managed" button.
111120
visitUrlWithManagedDisabled('/account/settings');
112-
cy.wait(['@getAccount', '@getProfile']);
121+
cy.wait(['@getAccount', '@getProfile', '@getGrants']);
113122

114123
ui.button
115124
.findByTitle('Add Linode Managed')

packages/manager/cypress/e2e/core/account/account-login-history.spec.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
* @file Integration tests for Cloud Manager account login history flows.
33
*/
44

5-
import { profileFactory } from '@linode/utilities';
5+
import { grantsFactory, profileFactory } from '@linode/utilities';
66
import {
77
loginEmptyStateMessageText,
88
loginHelperText,
99
} from 'support/constants/account';
1010
import { mockGetAccountLogins } from 'support/intercepts/account';
11-
import { mockGetProfile } from 'support/intercepts/profile';
11+
import {
12+
mockGetProfile,
13+
mockGetProfileGrants,
14+
} from 'support/intercepts/profile';
1215

1316
import { accountLoginFactory } from 'src/factories/accountLogin';
1417
import { PARENT_USER } from 'src/features/Account/constants';
@@ -100,12 +103,14 @@ describe('Account login history', () => {
100103
user_type: 'child',
101104
username: 'mock-child-user',
102105
});
106+
const mockGrants = grantsFactory.build();
103107

104108
mockGetProfile(mockProfile).as('getProfile');
109+
mockGetProfileGrants(mockGrants).as('getGrants');
105110

106111
// Navigate to Account Login History page.
107112
cy.visitWithLogin('/account/login-history');
108-
cy.wait(['@getProfile']);
113+
cy.wait(['@getProfile', '@getGrants']);
109114

110115
// Confirm helper text above table and table are not visible.
111116
cy.findByText(loginHelperText).should('not.exist');
@@ -149,12 +154,14 @@ describe('Account login history', () => {
149154
user_type: 'default',
150155
username: 'mock-restricted-user',
151156
});
157+
const mockGrants = grantsFactory.build();
152158

159+
mockGetProfileGrants(mockGrants).as('getGrants');
153160
mockGetProfile(mockProfile).as('getProfile');
154161

155162
// Navigate to Account Login History page.
156163
cy.visitWithLogin('/account/login-history');
157-
cy.wait(['@getProfile']);
164+
cy.wait(['@getProfile', '@getGrants']);
158165

159166
// Confirm helper text above table and table are not visible.
160167
cy.findByText(loginHelperText).should('not.exist');

packages/manager/cypress/e2e/core/account/display-settings.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { profileFactory } from '@linode/utilities';
1+
import { grantsFactory, profileFactory } from '@linode/utilities';
22
import { getProfile } from 'support/api/account';
33
import { mockUpdateUsername } from 'support/intercepts/account';
4-
import { interceptGetProfile } from 'support/intercepts/profile';
4+
import {
5+
interceptGetProfile,
6+
mockGetProfileGrants,
7+
} from 'support/intercepts/profile';
58
import { mockGetProfile } from 'support/intercepts/profile';
69
import { ui } from 'support/ui';
710
import { randomString } from 'support/util/random';
@@ -96,6 +99,9 @@ describe('Display Settings', () => {
9699
username: 'restricted-proxy-user',
97100
});
98101

102+
const mockGrants = grantsFactory.build();
103+
mockGetProfileGrants(mockGrants);
104+
99105
verifyUsernameAndEmail(
100106
mockRestrictedProxyProfile,
101107
RESTRICTED_FIELD_TOOLTIP,
@@ -123,6 +129,9 @@ describe('Display Settings', () => {
123129
username: 'regular-restricted-user',
124130
});
125131

132+
const mockGrants = grantsFactory.build();
133+
mockGetProfileGrants(mockGrants);
134+
126135
verifyUsernameAndEmail(
127136
mockRegularRestrictedProfile,
128137
'Restricted users cannot update their username. Please contact an account administrator.',

packages/manager/cypress/e2e/core/account/restricted-user-details-pages.spec.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,6 @@ describe('restricted user details pages', () => {
249249
cy.visitWithLogin(`/images`);
250250
cy.wait(['@getCustomImages', '@getProfile', '@getRecoveryImages']);
251251

252-
cy.findByText(
253-
`You don't have permissions to create Images. Please contact your ${ADMINISTRATOR} to request the necessary permissions.`
254-
);
255-
256252
// Confirm that the "Create Image" button is visible and disabled
257253
ui.button
258254
.findByTitle('Create Image')
@@ -307,11 +303,6 @@ describe('restricted user details pages', () => {
307303

308304
cy.wait(['@getProfile', '@getVolumes']);
309305

310-
// Confirm that a warning message is displayed
311-
cy.findByText(
312-
`You don't have permissions to create or edit Volumes. Please contact your ${ADMINISTRATOR} to request the necessary permissions.`
313-
);
314-
315306
// Confirm that the "Create Volume" button is disabled
316307
ui.button
317308
.findByTitle('Create Volume')
@@ -587,11 +578,6 @@ describe('restricted user details pages', () => {
587578
cy.visitWithLogin('/longview');
588579
cy.wait(['@getProfile', '@getLongviewClients']);
589580

590-
// Confirm that the warning message is displayed
591-
cy.findByText(
592-
`You don't have permissions to create Longview Clients. Please contact your ${ADMINISTRATOR} to request the necessary permissions.`
593-
);
594-
595581
// Confirm that the "Add Client" button is disabled
596582
ui.button
597583
.findByTitle('Add Client')

packages/manager/cypress/e2e/core/account/user-permissions.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ describe('User permission management', () => {
279279
...mockUserGrants,
280280
global: {
281281
account_access: 'read_only',
282-
add_buckets: true,
283282
add_databases: true,
284283
add_domains: true,
285284
add_firewalls: true,

packages/manager/cypress/e2e/core/objectStorageGen2/bucket-access-keys-gen2.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { profileFactory, regionFactory } from '@linode/utilities';
1+
import {
2+
grantsFactory,
3+
profileFactory,
4+
regionFactory,
5+
} from '@linode/utilities';
26
import { mockGetAccount } from 'support/intercepts/account';
37
import { mockAppendFeatureFlags } from 'support/intercepts/feature-flags';
48
import {
59
mockGetAccessKeys,
610
mockGetObjectStorageEndpoints,
711
} from 'support/intercepts/object-storage';
8-
import { mockGetProfile } from 'support/intercepts/profile';
12+
import {
13+
mockGetProfile,
14+
mockGetProfileGrants,
15+
} from 'support/intercepts/profile';
916
import { mockGetRegions } from 'support/intercepts/regions';
1017
import { ui } from 'support/ui';
1118

@@ -206,6 +213,7 @@ describe('Object Storage Gen2 create access key modal has disabled fields for re
206213
restricted: true,
207214
})
208215
).as('getProfile');
216+
mockGetProfileGrants(grantsFactory.build());
209217
});
210218

211219
// access keys creation

packages/manager/cypress/e2e/core/objectStorageGen2/bucket-create-gen2.spec.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { profileFactory, regionFactory } from '@linode/utilities';
1+
import {
2+
grantsFactory,
3+
profileFactory,
4+
regionFactory,
5+
} from '@linode/utilities';
26
import { mockGetAccount } from 'support/intercepts/account';
37
import { mockAppendFeatureFlags } from 'support/intercepts/feature-flags';
48
import {
@@ -9,7 +13,10 @@ import {
913
mockGetBuckets,
1014
mockGetObjectStorageEndpoints,
1115
} from 'support/intercepts/object-storage';
12-
import { mockGetProfile } from 'support/intercepts/profile';
16+
import {
17+
mockGetProfile,
18+
mockGetProfileGrants,
19+
} from 'support/intercepts/profile';
1320
import { mockGetRegions } from 'support/intercepts/regions';
1421
import { ui } from 'support/ui';
1522
import { checkRateLimitsTable } from 'support/util/object-storage-gen2';
@@ -756,12 +763,13 @@ describe('Object Storage Gen2 create bucket modal has disabled fields for restri
756763
restricted: true,
757764
})
758765
).as('getProfile');
766+
mockGetProfileGrants(grantsFactory.build()).as('getGrants');
759767
});
760768

761769
// bucket creation
762770
it('create bucket form', () => {
763771
cy.visitWithLogin('/object-storage/buckets/create');
764-
cy.wait(['@getFeatureFlags', '@getAccount', '@getProfile']);
772+
cy.wait(['@getFeatureFlags', '@getAccount', '@getProfile', '@getGrants']);
765773

766774
// error message
767775
ui.drawer

packages/manager/cypress/e2e/core/parentChild/token-scopes.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { profileFactory } from '@linode/utilities';
1+
import { grantsFactory, profileFactory } from '@linode/utilities';
22
import { accountFactory, appTokenFactory } from '@src/factories';
33
import { accountUserFactory } from '@src/factories/accountUsers';
44
import { DateTime } from 'luxon';
@@ -12,6 +12,7 @@ import {
1212
mockGetAppTokens,
1313
mockGetPersonalAccessTokens,
1414
mockGetProfile,
15+
mockGetProfileGrants,
1516
} from 'support/intercepts/profile';
1617
import { ui } from 'support/ui';
1718
import { randomLabel, randomNumber, randomString } from 'support/util/random';
@@ -25,6 +26,8 @@ const mockParentProfile = profileFactory.build({
2526
username: randomLabel(),
2627
});
2728

29+
const mockGrants = grantsFactory.build();
30+
2831
const mockParentUser = accountUserFactory.build({
2932
user_type: 'parent',
3033
username: mockParentProfile.username,
@@ -55,6 +58,7 @@ describe('Token scopes', () => {
5558
mockGetAccount(mockParentAccount);
5659
mockGetChildAccounts([mockChildAccount]);
5760
mockGetProfile({ ...mockParentProfile, restricted: true });
61+
mockGetProfileGrants(mockGrants);
5862
mockGetUser(mockParentUser);
5963

6064
mockGetPersonalAccessTokens([]).as('getTokens');

packages/manager/src/GoTo.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1+
import { useAccountSettings, useGrants, useProfile } from '@linode/queries';
12
import { Dialog, Select } from '@linode/ui';
23
import * as React from 'react';
34
import { useHistory } from 'react-router-dom';
45

56
import { useIsDatabasesEnabled } from './features/Databases/utilities';
67
import { useIsPlacementGroupsEnabled } from './features/PlacementGroups/utils';
7-
import { useAccountManagement } from './hooks/useAccountManagement';
88
import { useGlobalKeyboardListener } from './hooks/useGlobalKeyboardListener';
99

1010
import type { SelectOption } from '@linode/ui';
1111

1212
export const GoTo = React.memo(() => {
1313
const routerHistory = useHistory();
14-
const { _hasAccountAccess, _isManagedAccount } = useAccountManagement();
14+
15+
const { data: accountSettings } = useAccountSettings();
16+
const { data: grants } = useGrants();
17+
const { data: profile } = useProfile();
18+
19+
const isManagedAccount = accountSettings?.managed ?? false;
20+
21+
const hasAccountAccess =
22+
!profile?.restricted || Boolean(grants?.global.account_access);
1523

1624
const { isPlacementGroupsEnabled } = useIsPlacementGroupsEnabled();
1725
const { isDatabasesEnabled } = useIsDatabasesEnabled();
@@ -30,7 +38,7 @@ export const GoTo = React.memo(() => {
3038
() => [
3139
{
3240
display: 'Managed',
33-
hide: !_isManagedAccount,
41+
hide: !isManagedAccount,
3442
href: '/managed',
3543
},
3644
{
@@ -97,7 +105,7 @@ export const GoTo = React.memo(() => {
97105
},
98106
{
99107
display: 'Account',
100-
hide: !_hasAccountAccess,
108+
hide: !hasAccountAccess,
101109
href: '/account/billing',
102110
},
103111
{
@@ -109,7 +117,7 @@ export const GoTo = React.memo(() => {
109117
href: '/profile/display',
110118
},
111119
],
112-
[_hasAccountAccess, _isManagedAccount, isPlacementGroupsEnabled]
120+
[hasAccountAccess, isManagedAccount, isPlacementGroupsEnabled]
113121
);
114122

115123
const options: SelectOption<string>[] = React.useMemo(

0 commit comments

Comments
 (0)