X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/17d467bf2fecc68a6d66beea293cf23a38f95a53..bf5bf5faa1f61a2b78ff6153daff70a7bb08e939:/src/store/keep-services/keep-services-actions.ts diff --git a/src/store/keep-services/keep-services-actions.ts b/src/store/keep-services/keep-services-actions.ts index bf7c45ec..4eb5fc95 100644 --- a/src/store/keep-services/keep-services-actions.ts +++ b/src/store/keep-services/keep-services-actions.ts @@ -9,12 +9,12 @@ import { setBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions'; import { ServiceRepository } from "~/services/services"; import { KeepServiceResource } from '~/models/keep-services'; import { dialogActions } from '~/store/dialog/dialog-actions'; -import { snackbarActions } from '~/store/snackbar/snackbar-actions'; +import {snackbarActions, SnackbarKind} from '~/store/snackbar/snackbar-actions'; +import { navigateToRootProject } from '~/store/navigation/navigation-action'; export const keepServicesActions = unionize({ SET_KEEP_SERVICES: ofType(), - REMOVE_KEEP_SERVICE: ofType(), - RESET_KEEP_SERVICES: ofType<{}>() + REMOVE_KEEP_SERVICE: ofType() }); export type KeepServicesActions = UnionOf; @@ -22,21 +22,26 @@ export type KeepServicesActions = UnionOf; export const KEEP_SERVICE_REMOVE_DIALOG = 'keepServiceRemoveDialog'; export const KEEP_SERVICE_ATTRIBUTES_DIALOG = 'keepServiceAttributesDialog'; -// ToDo: access denied for loading keepService and reset data and redirect export const loadKeepServicesPanel = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - try { - dispatch(setBreadcrumbs([{ label: 'Keep Services' }])); - const response = await services.keepService.list(); - dispatch(keepServicesActions.SET_KEEP_SERVICES(response.items)); - } catch (e) { - return; + const user = getState().auth.user; + if(user && user.isAdmin) { + try { + dispatch(setBreadcrumbs([{ label: 'Keep Services' }])); + const response = await services.keepService.list(); + dispatch(keepServicesActions.SET_KEEP_SERVICES(response.items)); + } catch (e) { + return; + } + } else { + dispatch(navigateToRootProject); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: "You don't have permissions to view this page", hideDuration: 2000, kind: SnackbarKind.ERROR })); } }; -export const openKeepServiceAttributesDialog = (index: number) => +export const openKeepServiceAttributesDialog = (uuid: string) => (dispatch: Dispatch, getState: () => RootState) => { - const keepService = getState().keepServices[index]; + const keepService = getState().keepServices.find(it => it.uuid === uuid); dispatch(dialogActions.OPEN_DIALOG({ id: KEEP_SERVICE_ATTRIBUTES_DIALOG, data: { keepService } })); }; @@ -53,14 +58,13 @@ export const openKeepServiceRemoveDialog = (uuid: string) => })); }; -// ToDo: access denied for removing keepService and reset data and redirect export const removeKeepService = (uuid: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...' })); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...', kind: SnackbarKind.INFO })); try { await services.keepService.delete(uuid); dispatch(keepServicesActions.REMOVE_KEEP_SERVICE(uuid)); - dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Keep service has been successfully removed.', hideDuration: 2000 })); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Keep service has been successfully removed.', hideDuration: 2000, kind: SnackbarKind.SUCCESS })); } catch (e) { return; }