X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/4ab30205d4a2ea82d6fd4a71798ec2e1eba4ac0a..7a81b9d2c37ceb5add5df8fe9fe48b409d971e37:/src/store/auth/auth-action.ts diff --git a/src/store/auth/auth-action.ts b/src/store/auth/auth-action.ts index 28559b1a..d72a3ece 100644 --- a/src/store/auth/auth-action.ts +++ b/src/store/auth/auth-action.ts @@ -4,7 +4,7 @@ import { ofType, unionize, UnionOf } from '~/common/unionize'; import { Dispatch } from "redux"; -import { reset, stopSubmit, startSubmit } from 'redux-form'; +import { reset, stopSubmit, startSubmit, FormErrors } from 'redux-form'; import { AxiosInstance } from "axios"; import { RootState } from "../store"; import { snackbarActions } from '~/store/snackbar/snackbar-actions'; @@ -14,6 +14,7 @@ import { ServiceRepository } from "~/services/services"; import { getAuthorizedKeysServiceError, AuthorizedKeysServiceError } from '~/services/authorized-keys-service/authorized-keys-service'; import { KeyType, SshKeyResource } from '~/models/ssh-key'; import { User } from "~/models/user"; +import * as Routes from '~/routes/routes'; export const authActions = unionize({ SAVE_API_TOKEN: ofType(), @@ -94,9 +95,9 @@ export const openSshKeyCreateDialog = () => dialogActions.OPEN_DIALOG({ id: SSH_ export const openPublicKeyDialog = (name: string, publicKey: string) => dialogActions.OPEN_DIALOG({ id: SSH_KEY_PUBLIC_KEY_DIALOG, data: { name, publicKey } }); -export const openSshKeyAttributesDialog = (index: number) => +export const openSshKeyAttributesDialog = (uuid: string) => (dispatch: Dispatch, getState: () => RootState) => { - const sshKey = getState().auth.sshKeys[index]; + const sshKey = getState().auth.sshKeys.find(it => it.uuid === uuid); dispatch(dialogActions.OPEN_DIALOG({ id: SSH_KEY_ATTRIBUTES_DIALOG, data: { sshKey } })); }; @@ -143,9 +144,9 @@ export const createSshKey = (data: SshKeyCreateFormDialogData) => } catch (e) { const error = getAuthorizedKeysServiceError(e); if (error === AuthorizedKeysServiceError.UNIQUE_PUBLIC_KEY) { - dispatch(stopSubmit(SSH_KEY_CREATE_FORM_NAME, { publicKey: 'Public key already exists.' })); + dispatch(stopSubmit(SSH_KEY_CREATE_FORM_NAME, { publicKey: 'Public key already exists.' } as FormErrors)); } else if (error === AuthorizedKeysServiceError.INVALID_PUBLIC_KEY) { - dispatch(stopSubmit(SSH_KEY_CREATE_FORM_NAME, { publicKey: 'Public key is invalid' })); + dispatch(stopSubmit(SSH_KEY_CREATE_FORM_NAME, { publicKey: 'Public key is invalid' } as FormErrors)); } } }; @@ -153,13 +154,16 @@ export const createSshKey = (data: SshKeyCreateFormDialogData) => export const loadSshKeysPanel = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { try { - dispatch(setBreadcrumbs([{ label: 'SSH Keys'}])); + const userUuid = getState().auth.user!.uuid; + const { router } = getState(); + const pathname = router.location ? router.location.pathname : ''; + dispatch(setBreadcrumbs([{ label: 'SSH Keys' }])); const response = await services.authorizedKeysService.list(); - dispatch(authActions.SET_SSH_KEYS(response.items)); + const userSshKeys = response.items.find(it => it.ownerUuid === userUuid); + return Routes.matchSshKeysAdminRoute(pathname) ? dispatch(authActions.SET_SSH_KEYS(response.items)) : dispatch(authActions.SET_SSH_KEYS([userSshKeys!])); } catch (e) { return; } }; - export type AuthAction = UnionOf;