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<string>(),
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 } }));
};
export const loadSshKeysPanel = () =>
async (dispatch: Dispatch<any>, 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<typeof authActions>;