From 5017989693137cabe7f00a00c51db35625f9b55f Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Thu, 27 Dec 2018 09:36:04 +0100 Subject: [PATCH] login-as-someone Feature #14565 Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- src/store/auth/auth-action-session.ts | 4 ++-- src/store/users/users-actions.ts | 10 ++++++++++ src/views-components/user-dialog/manage-dialog.tsx | 10 ++++++---- src/views/user-panel/user-panel.tsx | 13 +++---------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/store/auth/auth-action-session.ts b/src/store/auth/auth-action-session.ts index e5e2e575..d36d5a33 100644 --- a/src/store/auth/auth-action-session.ts +++ b/src/store/auth/auth-action-session.ts @@ -80,7 +80,7 @@ const getSaltedToken = (clusterId: string, tokenUuid: string, token: string) => return `v2/${tokenUuid}/${hmac}`; }; -const clusterLogin = async (clusterId: string, baseUrl: string, activeSession: Session): Promise<{user: User, token: string}> => { +const clusterLogin = async (clusterId: string, baseUrl: string, activeSession: Session): Promise<{ user: User, token: string }> => { const tokenUuid = await getTokenUuid(activeSession.baseUrl, activeSession.token); const saltedToken = getSaltedToken(clusterId, tokenUuid, activeSession.token); const user = await getUserDetails(baseUrl, saltedToken); @@ -207,7 +207,7 @@ export const initSessions = (authService: AuthService, config: Config, user: Use export const loadSiteManagerPanel = () => async (dispatch: Dispatch) => { try { - dispatch(setBreadcrumbs([{ label: 'Site Manager'}])); + dispatch(setBreadcrumbs([{ label: 'Site Manager' }])); dispatch(validateSessions()); } catch (e) { return; diff --git a/src/store/users/users-actions.ts b/src/store/users/users-actions.ts index 9e76396d..e4465ddc 100644 --- a/src/store/users/users-actions.ts +++ b/src/store/users/users-actions.ts @@ -12,6 +12,7 @@ import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions import { UserResource } from "~/models/user"; import { getResource } from '~/store/resources/resources'; import { navigateToProject, navigateToUsers, navigateToRootProject } from "~/store/navigation/navigation-action"; +import { saveApiToken } from '~/store/auth/auth-action'; export const USERS_PANEL_ID = 'usersPanel'; export const USER_ATTRIBUTES_DIALOG = 'userAttributesDialog'; @@ -44,9 +45,18 @@ export const openSetupShellAccount = (uuid: string) => const { resources } = getState(); const user = getResource(uuid)(resources); const virtualMachines = await services.virtualMachineService.list(); + dispatch(dialogActions.CLOSE_DIALOG({ id: USER_MANAGE_DIALOG })); dispatch(dialogActions.OPEN_DIALOG({ id: SETUP_SHELL_ACCOUNT_DIALOG, data: { user, ...virtualMachines } })); }; +export const loginAs = (uuid: string) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const client = await services.apiClientAuthorizationService.get(uuid); + dispatch(saveApiToken(client.apiToken)); + location.reload(); + dispatch(navigateToRootProject); + }; + export const openUserCreateDialog = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const userUuid = await services.authService.getUuid(); diff --git a/src/views-components/user-dialog/manage-dialog.tsx b/src/views-components/user-dialog/manage-dialog.tsx index ddf73fb3..a64b5082 100644 --- a/src/views-components/user-dialog/manage-dialog.tsx +++ b/src/views-components/user-dialog/manage-dialog.tsx @@ -9,7 +9,7 @@ import { withDialog } from '~/store/dialog/with-dialog'; import { WithStyles, withStyles } from '@material-ui/core/styles'; import { ArvadosTheme } from '~/common/custom-theme'; import { compose, Dispatch } from "redux"; -import { USER_MANAGE_DIALOG, openSetupShellAccount } from "~/store/users/users-actions"; +import { USER_MANAGE_DIALOG, openSetupShellAccount, loginAs } from "~/store/users/users-actions"; import { UserResource } from "~/models/user"; import { connect } from "react-redux"; @@ -28,10 +28,12 @@ interface UserManageDataProps { interface UserManageActionProps { openSetupShellAccount: (uuid: string) => void; + loginAs: (uuid: string) => void; } const mapDispatchToProps = (dispatch: Dispatch) => ({ - openSetupShellAccount: (uuid: string) => dispatch(openSetupShellAccount(uuid)) + openSetupShellAccount: (uuid: string) => dispatch(openSetupShellAccount(uuid)), + loginAs: (uuid: string) => dispatch(loginAs(uuid)) }); type UserManageProps = UserManageDataProps & UserManageActionProps & WithStyles; @@ -50,13 +52,13 @@ export const UserManageDialog = compose( As an admin, you can log in as this user. When you’ve finished, you will need to log out and log in again with your own account. - As an admin, you can setup a shell account for this user. The login name is automatically generated from the user's e-mail address. - diff --git a/src/views/user-panel/user-panel.tsx b/src/views/user-panel/user-panel.tsx index b152896f..c42036ed 100644 --- a/src/views/user-panel/user-panel.tsx +++ b/src/views/user-panel/user-panel.tsx @@ -28,6 +28,7 @@ import { compose, Dispatch } from 'redux'; import { UserResource } from '~/models/user'; import { ShareMeIcon, AddIcon } from '~/components/icon/icon'; import { USERS_PANEL_ID, openUserCreateDialog } from '~/store/users/users-actions'; +import { noop } from 'lodash'; type UserPanelRules = "button"; @@ -165,8 +166,8 @@ export const UserPanel = compose( { - this.props.handleRowDoubleClick(uuid); - } - - handleRowClick = () => { - return; - } } ); -- 2.30.2