17914: Replaces deprecated substr() with substring().
[arvados-workbench2.git] / src / store / auth / auth-action-ssh.ts
index 1fbdfdfa63a1b5d49aeb1ff056f3aa22b3c4fe6d..3ba5f3a9edeee7469d3500fb80d6c1c0ee2df0c9 100644 (file)
@@ -2,21 +2,20 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { dialogActions } from "~/store/dialog/dialog-actions";
+import { dialogActions } from "store/dialog/dialog-actions";
 import { Dispatch } from "redux";
-import { RootState } from "~/store/store";
-import { ServiceRepository } from "~/services/services";
-import {snackbarActions, SnackbarKind} from "~/store/snackbar/snackbar-actions";
+import { RootState } from "store/store";
+import { getUserUuid } from "common/getuser";
+import { ServiceRepository } from "services/services";
+import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
 import { FormErrors, reset, startSubmit, stopSubmit } from "redux-form";
-import { KeyType } from "~/models/ssh-key";
+import { KeyType } from "models/ssh-key";
 import {
     AuthorizedKeysServiceError,
     getAuthorizedKeysServiceError
-} from "~/services/authorized-keys-service/authorized-keys-service";
-import { setBreadcrumbs } from "~/store/breadcrumbs/breadcrumbs-actions";
-import {
-    authActions,
-} from "~/store/auth/auth-action";
+} from "services/authorized-keys-service/authorized-keys-service";
+import { setBreadcrumbs } from "store/breadcrumbs/breadcrumbs-actions";
+import { authActions } from "store/auth/auth-action";
 
 export const SSH_KEY_CREATE_FORM_NAME = 'sshKeyCreateFormName';
 export const SSH_KEY_PUBLIC_KEY_DIALOG = 'sshKeyPublicKeyDialog';
@@ -62,7 +61,8 @@ export const removeSshKey = (uuid: string) =>
 
 export const createSshKey = (data: SshKeyCreateFormDialogData) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const userUuid = getState().auth.user!.uuid;
+        const userUuid = getUserUuid(getState());
+        if (!userUuid) { return; }
         const { name, publicKey } = data;
         dispatch(startSubmit(SSH_KEY_CREATE_FORM_NAME));
         try {
@@ -93,11 +93,10 @@ export const createSshKey = (data: SshKeyCreateFormDialogData) =>
 export const loadSshKeysPanel = () =>
     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
         try {
-            dispatch(setBreadcrumbs([{ label: 'SSH Keys'}]));
+            dispatch(setBreadcrumbs([{ label: 'SSH Keys' }]));
             const response = await services.authorizedKeysService.list();
             dispatch(authActions.SET_SSH_KEYS(response.items));
         } catch (e) {
             return;
         }
     };
-