Skip to content

Commit 4bf06f0

Browse files
fix: [UIE-10253] - IAM Delegate: hide company name for users with no permission
1 parent 0ef1621 commit 4bf06f0

File tree

6 files changed

+19
-28
lines changed

6 files changed

+19
-28
lines changed

packages/manager/src/OAuth/oauth.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@linode/utilities';
66
import * as Sentry from '@sentry/react';
77

8-
import { clearStorage, clearUserInput, storage } from 'src/utilities/storage';
8+
import { clearUserInput, storage } from 'src/utilities/storage';
99

1010
import { getAppRoot, getClientId, getLoginURL } from './constants';
1111
import { generateCodeChallenge, generateCodeVerifier } from './pkce';
@@ -45,7 +45,6 @@ function clearNonceAndCodeVerifierFromLocalStorage() {
4545
function clearAllAuthDataFromLocalStorage() {
4646
clearNonceAndCodeVerifierFromLocalStorage();
4747
clearAuthDataFromLocalStorage();
48-
clearStorage('switch_account/company_name');
4948
}
5049

5150
export function clearStorageAndRedirectToLogout() {
@@ -106,7 +105,6 @@ export async function logout() {
106105

107106
clearUserInput();
108107
clearAuthDataFromLocalStorage();
109-
clearStorage('switch_account/company_name');
110108

111109
if (token) {
112110
const tokenWithoutPrefix = token.split(' ')[1];

packages/manager/src/features/Account/SwitchAccountDrawer.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,21 @@ import { useSwitchToParentAccount } from 'src/features/Account/SwitchAccounts/us
2020
import { setTokenInLocalStorage } from 'src/features/Account/SwitchAccounts/utils';
2121
import { useIsIAMDelegationEnabled } from 'src/features/IAM/hooks/useIsIAMEnabled';
2222
import { sendSwitchToParentAccountEvent } from 'src/utilities/analytics/customEventAnalytics';
23-
import { getStorage, setStorage, storage } from 'src/utilities/storage';
23+
import { getStorage, storage } from 'src/utilities/storage';
2424

2525
import { ChildAccountList } from './SwitchAccounts/ChildAccountList';
2626
import { ChildAccountsTable } from './SwitchAccounts/ChildAccountsTable';
2727
import { updateParentTokenInLocalStorage } from './SwitchAccounts/utils';
2828

2929
import type { APIError, Filter, UserType } from '@linode/api-v4';
3030

31-
const SWITCH_ACCOUNT_COMPANY_KEY = 'switch_account/company_name';
32-
3331
interface Props {
3432
onClose: () => void;
3533
open: boolean;
3634
userType: undefined | UserType;
3735
}
3836

3937
interface HandleSwitchToChildAccountProps {
40-
company?: string;
4138
currentTokenWithBearer?: string;
4239
euuid: string;
4340
event: React.MouseEvent<HTMLElement>;
@@ -131,12 +128,11 @@ export const SwitchAccountDrawer = (props: Props) => {
131128
event,
132129
onClose,
133130
userType,
134-
company,
135131
}: HandleSwitchToChildAccountProps) => {
136132
const isProxyOrDelegateUserType =
137133
userType === 'proxy' || userType === 'delegate';
134+
138135
try {
139-
setStorage(SWITCH_ACCOUNT_COMPANY_KEY, company ?? '');
140136
if (isProxyOrDelegateUserType) {
141137
// Revoke proxy token before switching accounts.
142138
await revokeToken().catch(() => {
@@ -166,7 +162,6 @@ export const SwitchAccountDrawer = (props: Props) => {
166162
location.replace('/linodes');
167163
} catch {
168164
// Error is handled by createTokenError.
169-
setStorage(SWITCH_ACCOUNT_COMPANY_KEY, '');
170165
}
171166
},
172167
[createToken, isProxyUserType, updateCurrentToken, revokeToken]

packages/manager/src/features/Account/SwitchAccounts/ChildAccountsTable.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ export interface ChildAccountsTableProps {
2626
euuid,
2727
event,
2828
onClose,
29-
company,
3029
userType,
3130
}: {
32-
company?: string;
3331
currentTokenWithBearer?: string;
3432
euuid: string;
3533
event: React.MouseEvent<HTMLElement>;
@@ -109,7 +107,6 @@ export const ChildAccountsTable = (props: ChildAccountsTableProps) => {
109107
onSwitchAccount({
110108
currentTokenWithBearer,
111109
euuid: childAccount.euuid,
112-
company: childAccount.company,
113110
event,
114111
onClose,
115112
userType,

packages/manager/src/features/Account/SwitchAccounts/useSwitchToParentAccount.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
import { PARENT_USER_SESSION_EXPIRED } from 'src/features/Account/constants';
4-
import { clearStorage, setStorage } from 'src/utilities/storage';
4+
import { setStorage } from 'src/utilities/storage';
55

66
import { useParentChildAuthentication } from './useParentChildAuthentication';
77

@@ -38,8 +38,7 @@ export const useSwitchToParentAccount = ({
3838

3939
// Flag to prevent multiple clicks on the switch account button.
4040
setSubmitting(true);
41-
// Clean up the company name in storage to prevent it from being used in the parent account after switching back from a child account.
42-
clearStorage('switch_account/company_name');
41+
4342
try {
4443
// Revoke proxy or delegate token before switching to parent account.
4544
await revokeToken().catch(() => {

packages/manager/src/features/TopMenu/UserMenu/UserMenu.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ export const UserMenu = React.memo(() => {
4343
const open = Boolean(anchorEl);
4444
const id = open ? 'user-menu-popover' : undefined;
4545

46-
const switchAccountCompanyName = getStorage('switch_account/company_name');
47-
4846
const companyNameOrEmail = getCompanyNameOrEmail({
49-
company: account?.company ? account?.company : switchAccountCompanyName,
47+
company: account?.company,
5048
profile,
5149
});
5250

@@ -84,9 +82,11 @@ export const UserMenu = React.memo(() => {
8482
setStorage('is_delegate_user_type', 'true');
8583
}
8684

87-
enqueueSnackbar(`Account switched to ${companyNameOrEmail}.`, {
88-
variant: 'success',
89-
});
85+
const message = companyNameOrEmail
86+
? `Account switched to ${companyNameOrEmail}.`
87+
: 'Account switched.';
88+
89+
enqueueSnackbar(message, { variant: 'success' });
9090
}
9191
}, [
9292
isProxyOrDelegateUserType,

packages/manager/src/features/TopMenu/UserMenu/UserMenuPopover.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,8 @@ export const UserMenuPopover = (props: UserMenuPopoverProps) => {
121121
}
122122
: undefined;
123123

124-
const switchAccountCompanyName = getStorage('switch_account/company_name');
125124
const companyNameOrEmail = getCompanyNameOrEmail({
126-
company: account?.company ? account?.company : switchAccountCompanyName,
125+
company: account?.company,
127126
profile,
128127
});
129128
const { data: parentProfile } = useProfile({ headers: proxyHeaders });
@@ -236,8 +235,11 @@ export const UserMenuPopover = (props: UserMenuPopoverProps) => {
236235
gap={(theme) => theme.tokens.spacing.S16}
237236
minWidth={250}
238237
>
239-
<Stack display="flex" gap={(theme) => theme.tokens.spacing.S8}>
240-
{canSwitchBetweenParentOrProxyAccount && (
238+
<Stack
239+
display="flex"
240+
gap={(theme) => (companyNameOrEmail ? theme.tokens.spacing.S8 : 0)}
241+
>
242+
{canSwitchBetweenParentOrProxyAccount && companyNameOrEmail && (
241243
<Typography
242244
sx={(theme) => ({
243245
color: theme.tokens.alias.Content.Text.Primary.Default,
@@ -253,8 +255,8 @@ export const UserMenuPopover = (props: UserMenuPopoverProps) => {
253255
font: theme.tokens.alias.Typography.Label.Bold.L,
254256
})}
255257
>
256-
{canSwitchBetweenParentOrProxyAccount && companyNameOrEmail
257-
? companyNameOrEmail
258+
{canSwitchBetweenParentOrProxyAccount
259+
? companyNameOrEmail || null
258260
: userName}
259261
</Typography>
260262
{canSwitchBetweenParentOrProxyAccount && (

0 commit comments

Comments
 (0)