From 88c4b93c3e4f05afff419374277299d61ac61176 Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Mon, 10 Dec 2018 11:04:15 +0100 Subject: [PATCH] ssh-keys-admin-user-panels Feature #14566 Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- src/components/icon/icon.tsx | 2 ++ src/routes/route-change-handlers.ts | 7 +++++-- src/routes/routes.ts | 12 ++++++++---- src/store/auth/auth-action.ts | 9 +++++++-- src/store/navigation/navigation-action.ts | 4 +++- src/views-components/main-app-bar/account-menu.tsx | 4 ++-- src/views-components/main-app-bar/admin-menu.tsx | 8 ++++---- .../main-content-bar/main-content-bar.tsx | 9 +++++---- src/views/repositories-panel/repositories-panel.tsx | 2 +- .../virtual-machine-user-panel.tsx | 2 +- src/views/workbench/workbench.tsx | 3 ++- 11 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/components/icon/icon.tsx b/src/components/icon/icon.tsx index 8049686f..c077f7a6 100644 --- a/src/components/icon/icon.tsx +++ b/src/components/icon/icon.tsx @@ -7,6 +7,7 @@ import Add from '@material-ui/icons/Add'; import ArrowBack from '@material-ui/icons/ArrowBack'; import ArrowDropDown from '@material-ui/icons/ArrowDropDown'; import BubbleChart from '@material-ui/icons/BubbleChart'; +import Build from '@material-ui/icons/Build'; import Cached from '@material-ui/icons/Cached'; import ChevronLeft from '@material-ui/icons/ChevronLeft'; import CloudUpload from '@material-ui/icons/CloudUpload'; @@ -55,6 +56,7 @@ export type IconType = React.SFC<{ className?: string, style?: object }>; export const AddIcon: IconType = (props) => ; export const AddFavoriteIcon: IconType = (props) => ; +export const AdminMenuIcon: IconType = (props) => ; export const AdvancedIcon: IconType = (props) => ; export const AttributesIcon: IconType = (props) => ; export const BackIcon: IconType = (props) => ; diff --git a/src/routes/route-change-handlers.ts b/src/routes/route-change-handlers.ts index e68c3c6c..4ea0925c 100644 --- a/src/routes/route-change-handlers.ts +++ b/src/routes/route-change-handlers.ts @@ -29,7 +29,8 @@ const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => { const virtualMachineUserMatch = Routes.matchUserVirtualMachineRoute(pathname); const virtualMachineAdminMatch = Routes.matchAdminVirtualMachineRoute(pathname); const workflowMatch = Routes.matchWorkflowRoute(pathname); - const sshKeysMatch = Routes.matchSshKeysRoute(pathname); + const sshKeysUserMatch = Routes.matchSshKeysUserRoute(pathname); + const sshKeysAdminMatch = Routes.matchSshKeysAdminRoute(pathname); const keepServicesMatch = Routes.matchKeepServicesRoute(pathname); const computeNodesMatch = Routes.matchComputeNodesRoute(pathname); const apiClientAuthorizationsMatch = Routes.matchApiClientAuthorizationsRoute(pathname); @@ -64,7 +65,9 @@ const handleLocationChange = (store: RootStore) => ({ pathname }: Location) => { store.dispatch(WorkbenchActions.loadVirtualMachines); } else if (repositoryMatch) { store.dispatch(WorkbenchActions.loadRepositories); - } else if (sshKeysMatch) { + } else if (sshKeysUserMatch) { + store.dispatch(WorkbenchActions.loadSshKeys); + } else if (sshKeysAdminMatch) { store.dispatch(WorkbenchActions.loadSshKeys); } else if (keepServicesMatch) { store.dispatch(WorkbenchActions.loadKeepServices); diff --git a/src/routes/routes.ts b/src/routes/routes.ts index a5a0af1b..f447975b 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -19,11 +19,12 @@ export const Routes = { REPOSITORIES: '/repositories', SHARED_WITH_ME: '/shared-with-me', RUN_PROCESS: '/run-process', - VIRTUAL_MACHINES_USER: '/virtual-machines-user', VIRTUAL_MACHINES_ADMIN: '/virtual-machines-admin', + VIRTUAL_MACHINES_USER: '/virtual-machines-user', WORKFLOWS: '/workflows', SEARCH_RESULTS: '/search-results', - SSH_KEYS: `/ssh-keys`, + SSH_KEYS_ADMIN: `/ssh-keys-admin`, + SSH_KEYS_USER: `/ssh-keys-user`, MY_ACCOUNT: '/my-account', KEEP_SERVICES: `/keep-services`, COMPUTE_NODES: `/nodes`, @@ -95,8 +96,11 @@ export const matchAdminVirtualMachineRoute = (route: string) => export const matchRepositoriesRoute = (route: string) => matchPath(route, { path: Routes.REPOSITORIES }); -export const matchSshKeysRoute = (route: string) => - matchPath(route, { path: Routes.SSH_KEYS }); +export const matchSshKeysUserRoute = (route: string) => + matchPath(route, { path: Routes.SSH_KEYS_USER }); + +export const matchSshKeysAdminRoute = (route: string) => + matchPath(route, { path: Routes.SSH_KEYS_ADMIN }); export const matchMyAccountRoute = (route: string) => matchPath(route, { path: Routes.MY_ACCOUNT }); diff --git a/src/store/auth/auth-action.ts b/src/store/auth/auth-action.ts index 1e2620e4..d72a3ece 100644 --- a/src/store/auth/auth-action.ts +++ b/src/store/auth/auth-action.ts @@ -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(), @@ -153,9 +154,13 @@ 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; } diff --git a/src/store/navigation/navigation-action.ts b/src/store/navigation/navigation-action.ts index d070fd0f..66fba9cf 100644 --- a/src/store/navigation/navigation-action.ts +++ b/src/store/navigation/navigation-action.ts @@ -68,7 +68,9 @@ export const navigateToAdminVirtualMachines = push(Routes.VIRTUAL_MACHINES_ADMIN export const navigateToRepositories = push(Routes.REPOSITORIES); -export const navigateToSshKeys= push(Routes.SSH_KEYS); +export const navigateToSshKeysAdmin= push(Routes.SSH_KEYS_ADMIN); + +export const navigateToSshKeysUser= push(Routes.SSH_KEYS_USER); export const navigateToMyAccount = push(Routes.MY_ACCOUNT); diff --git a/src/views-components/main-app-bar/account-menu.tsx b/src/views-components/main-app-bar/account-menu.tsx index 31a28ecf..1609aafa 100644 --- a/src/views-components/main-app-bar/account-menu.tsx +++ b/src/views-components/main-app-bar/account-menu.tsx @@ -12,7 +12,7 @@ import { logout } from '~/store/auth/auth-action'; import { RootState } from "~/store/store"; import { openCurrentTokenDialog } from '~/store/current-token-dialog/current-token-dialog-actions'; import { openRepositoriesPanel } from "~/store/repositories/repositories-actions"; -import { navigateToSshKeys, navigateToMyAccount } from '~/store/navigation/navigation-action'; +import { navigateToSshKeysUser, navigateToMyAccount } from '~/store/navigation/navigation-action'; import { openUserVirtualMachines } from "~/store/virtual-machines/virtual-machines-actions"; interface AccountMenuProps { @@ -36,7 +36,7 @@ export const AccountMenu = connect(mapStateToProps)( dispatch(openUserVirtualMachines())}>Virtual Machines {!user.isAdmin && dispatch(openRepositoriesPanel())}>Repositories} dispatch(openCurrentTokenDialog)}>Current token - dispatch(navigateToSshKeys)}>Ssh Keys + dispatch(navigateToSshKeysUser)}>Ssh Keys dispatch(navigateToMyAccount)}>My account dispatch(logout())}>Logout diff --git a/src/views-components/main-app-bar/admin-menu.tsx b/src/views-components/main-app-bar/admin-menu.tsx index f754c857..8185f471 100644 --- a/src/views-components/main-app-bar/admin-menu.tsx +++ b/src/views-components/main-app-bar/admin-menu.tsx @@ -6,13 +6,13 @@ import * as React from "react"; import { MenuItem } from "@material-ui/core"; import { User } from "~/models/user"; import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu"; -import { ShareMeIcon } from "~/components/icon/icon"; +import { AdminMenuIcon } from "~/components/icon/icon"; import { DispatchProp, connect } from 'react-redux'; import { logout } from '~/store/auth/auth-action'; import { RootState } from "~/store/store"; import { openRepositoriesPanel } from "~/store/repositories/repositories-actions"; import { - navigateToSshKeys, navigateToKeepServices, navigateToComputeNodes, + navigateToSshKeysAdmin, navigateToKeepServices, navigateToComputeNodes, navigateToApiClientAuthorizations } from '~/store/navigation/navigation-action'; import { openAdminVirtualMachines } from "~/store/virtual-machines/virtual-machines-actions"; @@ -30,12 +30,12 @@ export const AdminMenu = connect(mapStateToProps)( ({ user, dispatch }: AdminMenuProps & DispatchProp) => user ? } + icon={} id="admin-menu" title="Admin Panel"> dispatch(openRepositoriesPanel())}>Repositories dispatch(openAdminVirtualMachines())}>Virtual Machines - dispatch(navigateToSshKeys)}>Ssh Keys + dispatch(navigateToSshKeysAdmin)}>Ssh Keys dispatch(navigateToApiClientAuthorizations)}>Api Tokens dispatch(navigateToUsers)}>Users dispatch(navigateToComputeNodes)}>Compute Nodes diff --git a/src/views-components/main-content-bar/main-content-bar.tsx b/src/views-components/main-content-bar/main-content-bar.tsx index 944f135a..92592193 100644 --- a/src/views-components/main-content-bar/main-content-bar.tsx +++ b/src/views-components/main-content-bar/main-content-bar.tsx @@ -19,10 +19,11 @@ interface MainContentBarProps { const isButtonVisible = ({ router }: RootState) => { const pathname = router.location ? router.location.pathname : ''; return !Routes.matchWorkflowRoute(pathname) && !Routes.matchUserVirtualMachineRoute(pathname) && - !Routes.matchAdminVirtualMachineRoute(pathname) && !Routes.matchRepositoriesRoute(pathname) && - !Routes.matchSshKeysRoute(pathname) && !Routes.matchKeepServicesRoute(pathname) && - !Routes.matchComputeNodesRoute(pathname) && !Routes.matchApiClientAuthorizationsRoute(pathname) && - !Routes.matchUsersRoute(pathname) && !Routes.matchMyAccountRoute(pathname); + !Routes.matchAdminVirtualMachineRoute(pathname) && !Routes.matchRepositoriesRoute(pathname) && + !Routes.matchSshKeysAdminRoute(pathname) && !Routes.matchSshKeysUserRoute(pathname) && + !Routes.matchKeepServicesRoute(pathname) && !Routes.matchComputeNodesRoute(pathname) && + !Routes.matchApiClientAuthorizationsRoute(pathname) && !Routes.matchUsersRoute(pathname) && + !Routes.matchMyAccountRoute(pathname); }; export const MainContentBar = connect((state: RootState) => ({ diff --git a/src/views/repositories-panel/repositories-panel.tsx b/src/views/repositories-panel/repositories-panel.tsx index c7016f62..62e91b5f 100644 --- a/src/views/repositories-panel/repositories-panel.tsx +++ b/src/views/repositories-panel/repositories-panel.tsx @@ -103,7 +103,7 @@ export const RepositoriesPanel = compose( When you are using an Arvados virtual machine, you should clone the https:// URLs. This will authenticate automatically using your API token.
- In order to clone git repositories using SSH, add an SSH key to your account and clone the git@ URLs. + In order to clone git repositories using SSH, add an SSH key to your account and clone the git@ URLs.
diff --git a/src/views/virtual-machine-panel/virtual-machine-user-panel.tsx b/src/views/virtual-machine-panel/virtual-machine-user-panel.tsx index 17563053..fbb1f23f 100644 --- a/src/views/virtual-machine-panel/virtual-machine-user-panel.tsx +++ b/src/views/virtual-machine-panel/virtual-machine-user-panel.tsx @@ -187,7 +187,7 @@ const CardSSHSection = (props: VirtualMachineProps) => - In order to access virtual machines using SSH, add an SSH key to your account and add a section like this to your SSH configuration file ( ~/.ssh/config): + In order to access virtual machines using SSH, add an SSH key to your account and add a section like this to your SSH configuration file ( ~/.ssh/config): - + + -- 2.30.2