Skip to content

Commit d22474e

Browse files
fix: [UIE-10253] - IAM Delegate: company name for users with no permissions
1 parent 4366b2d commit d22474e

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ export const SwitchAccountButton = (props: ButtonProps) => {
1919
},
2020
font: theme.tokens.alias.Typography.Label.Semibold.S,
2121
marginTop: theme.tokens.spacing.S4,
22+
...(isDelegateUserType && {
23+
'&.MuiButton-root': {
24+
textTransform: 'none',
25+
},
26+
}),
2227
})}
2328
{...props}
2429
>
25-
{isDelegateUserType ? 'Switch back to your account' : 'Switch Account'}
30+
{isDelegateUserType ? 'Switch Back to Your Account' : 'Switch Account'}
2631
</Button>
2732
);
2833
};

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,24 @@ 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, storage } from 'src/utilities/storage';
23+
import { getStorage, setStorage, 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+
3133
interface Props {
3234
onClose: () => void;
3335
open: boolean;
3436
userType: undefined | UserType;
3537
}
3638

3739
interface HandleSwitchToChildAccountProps {
40+
company?: string;
3841
currentTokenWithBearer?: string;
3942
euuid: string;
4043
event: React.MouseEvent<HTMLElement>;
@@ -128,11 +131,12 @@ export const SwitchAccountDrawer = (props: Props) => {
128131
event,
129132
onClose,
130133
userType,
134+
company,
131135
}: HandleSwitchToChildAccountProps) => {
132136
const isProxyOrDelegateUserType =
133137
userType === 'proxy' || userType === 'delegate';
134-
135138
try {
139+
setStorage(SWITCH_ACCOUNT_COMPANY_KEY, company ?? '');
136140
if (isProxyOrDelegateUserType) {
137141
// Revoke proxy token before switching accounts.
138142
await revokeToken().catch(() => {
@@ -162,6 +166,7 @@ export const SwitchAccountDrawer = (props: Props) => {
162166
location.replace('/linodes');
163167
} catch {
164168
// Error is handled by createTokenError.
169+
setStorage(SWITCH_ACCOUNT_COMPANY_KEY, '');
165170
}
166171
},
167172
[createToken, isProxyUserType, updateCurrentToken, revokeToken]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ export interface ChildAccountsTableProps {
2626
euuid,
2727
event,
2828
onClose,
29+
company,
2930
userType,
3031
}: {
32+
company?: string;
3133
currentTokenWithBearer?: string;
3234
euuid: string;
3335
event: React.MouseEvent<HTMLElement>;
@@ -107,6 +109,7 @@ export const ChildAccountsTable = (props: ChildAccountsTableProps) => {
107109
onSwitchAccount({
108110
currentTokenWithBearer,
109111
euuid: childAccount.euuid,
112+
company: childAccount.company,
110113
event,
111114
onClose,
112115
userType,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ 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+
4648
const companyNameOrEmail = getCompanyNameOrEmail({
47-
company: account?.company,
49+
company: account?.company ? account?.company : switchAccountCompanyName,
4850
profile,
4951
});
5052

0 commit comments

Comments
 (0)