X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6faff5910b3e7bdaf47ab5ede7cf8094a1b4adb9..010156ef2c2c6977b9ad67fc613b369d8b3ae94f:/src/store/users/users-actions.ts diff --git a/src/store/users/users-actions.ts b/src/store/users/users-actions.ts index 9e76396d0e..caf466f7ed 100644 --- a/src/store/users/users-actions.ts +++ b/src/store/users/users-actions.ts @@ -12,11 +12,12 @@ 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'; export const USER_CREATE_FORM_NAME = 'userCreateFormName'; -export const USER_MANAGE_DIALOG = 'userManageDialog'; +export const USER_MANAGEMENT_DIALOG = 'userManageDialog'; export const SETUP_SHELL_ACCOUNT_DIALOG = 'setupShellAccountDialog'; export interface UserCreateFormDialogData { @@ -32,11 +33,11 @@ export const openUserAttributes = (uuid: string) => dispatch(dialogActions.OPEN_DIALOG({ id: USER_ATTRIBUTES_DIALOG, data })); }; -export const openUserManage = (uuid: string) => - (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { +export const openUserManagement = (uuid: string) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const { resources } = getState(); const data = getResource(uuid)(resources); - dispatch(dialogActions.OPEN_DIALOG({ id: USER_MANAGE_DIALOG, data })); + dispatch(dialogActions.OPEN_DIALOG({ id: USER_MANAGEMENT_DIALOG, data })); }; export const openSetupShellAccount = (uuid: string) => @@ -44,9 +45,23 @@ 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_MANAGEMENT_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 { resources } = getState(); + const data = getResource(uuid)(resources); + if (data) { + services.authService.saveUser(data); + } + const client = await services.apiClientAuthorizationService.create({ ownerUuid: uuid }); + dispatch(saveApiToken(`v2/${client.uuid}/${client.apiToken}`)); + location.reload(); + dispatch(navigateToRootProject); + }; + export const openUserCreateDialog = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const userUuid = await services.authService.getUuid();