Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/manager/src/features/Account/SwitchAccountDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const SwitchAccountDrawer = (props: Props) => {
filter,
headers: isProxyOrDelegateUserType
? {
Authorization: currentTokenWithBearer,
Authorization: currentParentTokenWithBearer,
}
: undefined,
},
Expand Down Expand Up @@ -146,17 +146,17 @@ export const SwitchAccountDrawer = (props: Props) => {
const proxyToken = await createToken(euuid);

setTokenInLocalStorage({
prefix: isProxyUserType
? 'authentication/proxy_token'
: 'authentication/delegate_token',
prefix: isIAMDelegationEnabled
? 'authentication/delegate_token'
: 'authentication/proxy_token',
token: {
...proxyToken,
token: `Bearer ${proxyToken.token}`,
},
});

updateCurrentToken({
userType: isProxyUserType ? 'proxy' : 'delegate',
userType: isIAMDelegationEnabled ? 'delegate' : 'proxy',
});
onClose(event);
location.reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { sessionExpirationContext as _sessionExpirationContext } from 'src/conte
import { useParentChildAuthentication } from 'src/features/Account/SwitchAccounts/useParentChildAuthentication';
import { setTokenInLocalStorage } from 'src/features/Account/SwitchAccounts/utils';
import { useDelegationRole } from 'src/features/IAM/hooks/useDelegationRole';
import { useIsIAMDelegationEnabled } from 'src/features/IAM/hooks/useIsIAMEnabled';
import { parseAPIDate } from 'src/utilities/date';
import { getStorage, setStorage } from 'src/utilities/storage';

Expand All @@ -23,6 +24,7 @@ export const SessionExpirationDialog = React.memo(
_sessionExpirationContext
);
const { isProxyUserType, isDelegateUserType } = useDelegationRole();
const { isIAMDelegationEnabled } = useIsIAMDelegationEnabled();

const [timeRemaining, setTimeRemaining] = React.useState<{
minutes: number;
Expand Down Expand Up @@ -112,18 +114,22 @@ export const SessionExpirationDialog = React.memo(

const proxyToken = await createToken(euuid);

const tokenPrefix = isIAMDelegationEnabled
? 'authentication/delegate_token'
: 'authentication/proxy_token';
const tokenUserType = isIAMDelegationEnabled ? 'delegate' : 'proxy';

setTokenInLocalStorage({
prefix: isProxyUserType
? 'authentication/proxy_token'
: 'authentication/delegate_token',
prefix: tokenPrefix,

token: {
...proxyToken,
token: `Bearer ${proxyToken.token}`,
},
});

updateCurrentToken({
userType: isProxyUserType ? 'proxy' : 'delegate',
userType: tokenUserType,
});
onClose();
location.reload();
Expand All @@ -139,7 +145,7 @@ export const SessionExpirationDialog = React.memo(
*/
useEffect(() => {
const checkTokenExpiry = () => {
const expiryString = isProxyUserType
const expiryString = isIAMDelegationEnabled
? getStorage('authentication/proxy_token/expire')
: getStorage('authentication/delegate_token/expire');

Expand Down
7 changes: 4 additions & 3 deletions packages/manager/src/features/TopMenu/UserMenu/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ export const UserMenu = React.memo(() => {
React.useEffect(() => {
// Run after we've switched to a proxy user.
if (
isProxyOrDelegateUserType &&
(!getStorage('is_proxy_user_type') ||
!getStorage('is_delegate_user_type'))
(isProxyOrDelegateUserType &&
isProxyUserType &&
!getStorage('is_proxy_user_type')) ||
(isDelegateUserType && !getStorage('is_delegate_user_type'))
) {
// Flag for proxy user to display success toast once.
if (isProxyUserType) {
Expand Down
94 changes: 39 additions & 55 deletions packages/manager/src/features/Users/UserPermissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,12 @@ class UserPermissions extends React.Component<CombinedProps, State> {
};

componentDidMount() {
this.getUserGrants();
this.getUserType();
this.getUserAndGrants();
}

componentDidUpdate(prevProps: CombinedProps) {
if (prevProps.currentUsername !== this.props.currentUsername) {
this.getUserGrants();
this.getUserType();
this.getUserAndGrants();
}
}

Expand Down Expand Up @@ -214,64 +212,50 @@ class UserPermissions extends React.Component<CombinedProps, State> {
{ showTabs: false, tabs: [] }
);

getUserGrants = () => {
getUserAndGrants = async () => {
const { currentUsername } = this.props;
if (currentUsername) {
getGrants(currentUsername)
.then((grants) => {
if (grants.global) {
const { showTabs, tabs } = this.getTabInformation(grants);

this.setState({
grants,
loading: false,
loadingGrants: false,
originalGrants: grants,
restricted: true,
showTabs,
tabs,
});
} else {
this.setState({
grants,
loading: false,
loadingGrants: false,
restricted: false,
});
}
})
.catch((errResponse) => {
this.setState({
errors: getAPIErrorOrDefault(
errResponse,
'Unknown error occurred while fetching user permissions. Try again later.'
),
});
scrollErrorIntoViewV2(this.formContainerRef);
});
if (!currentUsername) {
return;
}
};

getUserType = async () => {
const { currentUsername } = this.props;
try {
const user = await getUser(currentUsername);

// Current user is the user whose permissions are currently being viewed.
if (currentUsername) {
try {
const user = await getUser(currentUsername);
this.setState({
userType: user.user_type,
});

if (!user.restricted) {
this.setState({
userType: user.user_type,
});
} catch (error) {
this.setState({
errors: getAPIErrorOrDefault(
error,
'Unknown error occurred while fetching user permissions. Try again later.'
),
loading: false,
loadingGrants: false,
restricted: false,
});
scrollErrorIntoViewV2(this.formContainerRef);
return;
}

const grants = await getGrants(currentUsername);
const { showTabs, tabs } = this.getTabInformation(grants);

this.setState({
grants,
loading: false,
loadingGrants: false,
originalGrants: grants,
restricted: true,
showTabs,
tabs,
});
} catch (errResponse) {
this.setState({
errors: getAPIErrorOrDefault(
errResponse,
'Unknown error occurred while fetching user permissions. Try again later.'
),
loading: false,
loadingGrants: false,
});
scrollErrorIntoViewV2(this.formContainerRef);
}
};

Expand Down Expand Up @@ -303,7 +287,7 @@ class UserPermissions extends React.Component<CombinedProps, State> {
user
);
// unconditionally sets this.state.loadingGrants to false
this.getUserGrants();
this.getUserAndGrants();
enqueueSnackbar('User permissions successfully saved.', {
variant: 'success',
});
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/features/Users/UserRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface Props {

export const UserRow = ({ onDelete, user }: Props) => {
const theme = useTheme();
const { data: grants } = useAccountUserGrants(user.username);
const { data: grants } = useAccountUserGrants(user.username, user.restricted);
const { data: profile } = useProfile();

const isProxyOrDelegateUser = Boolean(
Expand Down
3 changes: 1 addition & 2 deletions packages/manager/src/features/Users/UsersLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const UsersLanding = () => {
const matchesLgUp = useMediaQuery(theme.breakpoints.up('lg'));
const {
isProxyOrDelegateUserType,
isProxyUserType,
isChildUserType,
isParentUserType,
profile,
Expand Down Expand Up @@ -88,7 +87,7 @@ export const UsersLanding = () => {
isInitialLoading: isLoadingProxyUser,
} = useAccountUsers({
enabled: showProxyOrDelegateUserTable && !isRestrictedUser,
filters: { user_type: isProxyUserType ? 'proxy' : 'delegate' },
filters: { user_type: 'proxy' },
});

const isChildAccountAccessRestricted = useRestrictedGlobalGrantCheck({
Expand Down
12 changes: 8 additions & 4 deletions packages/queries/src/account/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ export const useAccountUser = (username: string, enabled: boolean = true) => {
});
};

export const useAccountUserGrants = (username: string) => {
return useQuery<Grants, APIError[]>(
accountQueries.users._ctx.user(username)._ctx.grants,
);
export const useAccountUserGrants = (
username: string,
enabled: boolean = true,
) => {
return useQuery<Grants, APIError[]>({
...accountQueries.users._ctx.user(username)._ctx.grants,
enabled,
});
};

export const useUpdateUserMutation = (username: string) => {
Expand Down