merge master
[arvados-workbench2.git] / src / store / users / users-actions.ts
index 64c3646a36ae70be55af9470d1ad14ab43eee719..9e76396d0e7f3adafdf934da2fc83ee25534188c 100644 (file)
@@ -7,20 +7,20 @@ import { bindDataExplorerActions } from '~/store/data-explorer/data-explorer-act
 import { RootState } from '~/store/store';
 import { ServiceRepository } from "~/services/services";
 import { dialogActions } from '~/store/dialog/dialog-actions';
-import { startSubmit, reset, stopSubmit } from "redux-form";
-import { getCommonResourceServiceError, CommonResourceServiceError } from "~/services/common-service/common-resource-service";
+import { startSubmit, reset } from "redux-form";
 import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
 import { UserResource } from "~/models/user";
 import { getResource } from '~/store/resources/resources';
-import { navigateToProject } from "~/store/navigation/navigation-action";
+import { navigateToProject, navigateToUsers, navigateToRootProject } from "~/store/navigation/navigation-action";
 
 export const USERS_PANEL_ID = 'usersPanel';
 export const USER_ATTRIBUTES_DIALOG = 'userAttributesDialog';
-export const USER_CREATE_FORM_NAME = 'repositoryCreateFormName';
+export const USER_CREATE_FORM_NAME = 'userCreateFormName';
+export const USER_MANAGE_DIALOG = 'userManageDialog';
+export const SETUP_SHELL_ACCOUNT_DIALOG = 'setupShellAccountDialog';
 
 export interface UserCreateFormDialogData {
     email: string;
-    identityUrl: string;
     virtualMachineName: string;
     groupVirtualMachine: string;
 }
@@ -32,6 +32,21 @@ 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) => {
+        const { resources } = getState();
+        const data = getResource<UserResource>(uuid)(resources);
+        dispatch(dialogActions.OPEN_DIALOG({ id: USER_MANAGE_DIALOG, data }));
+    };
+
+export const openSetupShellAccount = (uuid: string) =>
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+        const { resources } = getState();
+        const user = getResource<UserResource>(uuid)(resources);
+        const virtualMachines = await services.virtualMachineService.list();
+        dispatch(dialogActions.OPEN_DIALOG({ id: SETUP_SHELL_ACCOUNT_DIALOG, data: { user, ...virtualMachines } }));
+    };
+
 export const openUserCreateDialog = () =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const userUuid = await services.authService.getUuid();
@@ -59,7 +74,18 @@ export const createUser = (user: UserCreateFormDialogData) =>
             dispatch(userBindedActions.REQUEST_ITEMS());
             return newUser;
         } catch (e) {
-            return ;
+            return;
+        }
+    };
+
+export const openUserPanel = () =>
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+        const user = getState().auth.user;
+        if (user && user.isAdmin) {
+            dispatch<any>(navigateToUsers);
+        } else {
+            dispatch<any>(navigateToRootProject);
+            dispatch(snackbarActions.OPEN_SNACKBAR({ message: "You don't have permissions to view this page", hideDuration: 2000 }));
         }
     };