From 37504d34196d446ae8fa2e01fa84bdc0ecbbed78 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Wed, 24 May 2023 16:32:43 -0400 Subject: [PATCH] 20538: Add 403 error handling to remove process action and suppress errors from the containerRequestService Arvados-DCO-1.1-Signed-off-by: Stephen Smith --- .../common-service/common-resource-service.ts | 5 +++-- src/store/processes/processes-actions.ts | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/services/common-service/common-resource-service.ts b/src/services/common-service/common-resource-service.ts index d9be8dae..515eb6a4 100644 --- a/src/services/common-service/common-resource-service.ts +++ b/src/services/common-service/common-resource-service.ts @@ -13,6 +13,7 @@ export enum CommonResourceServiceError { OWNERSHIP_CYCLE = 'OwnershipCycle', MODIFYING_CONTAINER_REQUEST_FINAL_STATE = 'ModifyingContainerRequestFinalState', NAME_HAS_ALREADY_BEEN_TAKEN = 'NameHasAlreadyBeenTaken', + PERMISSION_ERROR_FORBIDDEN = 'PermissionErrorForbidden', UNKNOWN = 'Unknown', NONE = 'None' } @@ -64,11 +65,11 @@ export const getCommonResourceServiceError = (errorResponse: any) => { return CommonResourceServiceError.MODIFYING_CONTAINER_REQUEST_FINAL_STATE; case /Name has already been taken/.test(error): return CommonResourceServiceError.NAME_HAS_ALREADY_BEEN_TAKEN; + case /403 Forbidden/.test(error): + return CommonResourceServiceError.PERMISSION_ERROR_FORBIDDEN; default: return CommonResourceServiceError.UNKNOWN; } } return CommonResourceServiceError.NONE; }; - - diff --git a/src/store/processes/processes-actions.ts b/src/store/processes/processes-actions.ts index b26c2017..4a27cba6 100644 --- a/src/store/processes/processes-actions.ts +++ b/src/store/processes/processes-actions.ts @@ -24,6 +24,7 @@ import { CommandOutputParameter } from "cwlts/mappings/v1.0/CommandOutputParamet import { ContainerResource } from "models/container"; import { ContainerRequestResource, ContainerRequestState } from "models/container-request"; import { FilterBuilder } from "services/api/filter-builder"; +import { CommonResourceServiceError, getCommonResourceServiceError } from "services/common-service/common-resource-service"; export const loadProcess = (containerRequestUuid: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise => { @@ -291,8 +292,17 @@ export const REMOVE_PROCESS_DIALOG = 'removeProcessDialog'; export const removeProcessPermanently = (uuid: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...', kind: SnackbarKind.INFO })); - await services.containerRequestService.delete(uuid); - dispatch(projectPanelActions.REQUEST_ITEMS()); - dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removed.', hideDuration: 2000, kind: SnackbarKind.SUCCESS })); + try { + dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...', kind: SnackbarKind.INFO })); + await services.containerRequestService.delete(uuid, false); + dispatch(projectPanelActions.REQUEST_ITEMS()); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removed.', hideDuration: 2000, kind: SnackbarKind.SUCCESS })); + } catch(e) { + const error = getCommonResourceServiceError(e); + if (error === CommonResourceServiceError.PERMISSION_ERROR_FORBIDDEN) { + dispatch(snackbarActions.OPEN_SNACKBAR({ message: `Access denied`, hideDuration: 2000, kind: SnackbarKind.ERROR })); + } else { + dispatch(snackbarActions.OPEN_SNACKBAR({ message: `Deletion failed`, hideDuration: 2000, kind: SnackbarKind.ERROR })); + } + } }; -- 2.30.2