From 5c1516ca6ec8d4afb2546f316669695a0976223a Mon Sep 17 00:00:00 2001 From: Xavier Mouligneau <189600+XavierM@users.noreply.github.com> Date: Thu, 2 Apr 2020 08:55:07 -0400 Subject: [PATCH] [SIEM] CASES Bugs BC2 (#62170) (#62231) * fix persistence between filter * Fix API filtering bug * Show username if full name is empty * fix user in avatar * do not allow push to service now when connector is none * fix types * Show errors from actions * update connector name in configure Co-authored-by: Christos Nasikas Co-authored-by: Christos Nasikas --- .../siem/public/containers/case/api.ts | 7 ++++++ .../case/configure/use_configure.tsx | 23 +++++++++++-------- .../public/containers/case/translations.ts | 7 ++++++ .../public/containers/case/use_get_cases.tsx | 15 +++++++----- .../case/components/all_cases/columns.tsx | 2 +- .../pages/case/components/all_cases/index.tsx | 6 ++--- .../components/use_push_to_service/index.tsx | 6 ++++- .../user_action_tree/user_action_item.tsx | 4 ++-- .../server/routes/api/cases/find_cases.ts | 5 ++-- 9 files changed, 51 insertions(+), 24 deletions(-) diff --git a/x-pack/legacy/plugins/siem/public/containers/case/api.ts b/x-pack/legacy/plugins/siem/public/containers/case/api.ts index bd243d0ba5f64..69e1602b3d981 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/api.ts +++ b/x-pack/legacy/plugins/siem/public/containers/case/api.ts @@ -47,6 +47,8 @@ import { decodeServiceConnectorCaseResponse, } from './utils'; +import * as i18n from './translations'; + export const getCase = async ( caseId: string, includeComments: boolean = true, @@ -240,6 +242,11 @@ export const pushToService = async ( signal, } ); + + if (response.status === 'error') { + throw new Error(response.serviceMessage ?? response.message ?? i18n.ERROR_PUSH_TO_SERVICE); + } + return decodeServiceConnectorCaseResponse(response.data); }; diff --git a/x-pack/legacy/plugins/siem/public/containers/case/configure/use_configure.tsx b/x-pack/legacy/plugins/siem/public/containers/case/configure/use_configure.tsx index 6524c40a8e6e4..19d80bba1e0f8 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/configure/use_configure.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/case/configure/use_configure.tsx @@ -21,7 +21,11 @@ interface PersistCaseConfigure { export interface ReturnUseCaseConfigure { loading: boolean; refetchCaseConfigure: () => void; - persistCaseConfigure: ({ connectorId, closureType }: PersistCaseConfigure) => unknown; + persistCaseConfigure: ({ + connectorId, + connectorName, + closureType, + }: PersistCaseConfigure) => unknown; persistLoading: boolean; } @@ -97,19 +101,20 @@ export const useCaseConfigure = ({ const saveCaseConfiguration = async () => { try { setPersistLoading(true); + const connectorObj = { + connector_id: connectorId, + connector_name: connectorName, + closure_type: closureType, + }; const res = version.length === 0 - ? await postCaseConfigure( + ? await postCaseConfigure(connectorObj, abortCtrl.signal) + : await patchCaseConfigure( { - connector_id: connectorId, - connector_name: connectorName, - closure_type: closureType, + ...connectorObj, + version, }, abortCtrl.signal - ) - : await patchCaseConfigure( - { connector_id: connectorId, closure_type: closureType, version }, - abortCtrl.signal ); if (!didCancel) { setPersistLoading(false); diff --git a/x-pack/legacy/plugins/siem/public/containers/case/translations.ts b/x-pack/legacy/plugins/siem/public/containers/case/translations.ts index a453be32480e2..d5ea287fd2cdd 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/translations.ts +++ b/x-pack/legacy/plugins/siem/public/containers/case/translations.ts @@ -63,3 +63,10 @@ export const SUCCESS_SEND_TO_EXTERNAL_SERVICE = i18n.translate( defaultMessage: 'Successfully sent to ServiceNow', } ); + +export const ERROR_PUSH_TO_SERVICE = i18n.translate( + 'xpack.siem.case.configure.errorPushingToService', + { + defaultMessage: 'Error pushing to service', + } +); diff --git a/x-pack/legacy/plugins/siem/public/containers/case/use_get_cases.tsx b/x-pack/legacy/plugins/siem/public/containers/case/use_get_cases.tsx index 323dc23e1b24e..1cbce5af6304b 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/use_get_cases.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/case/use_get_cases.tsx @@ -35,7 +35,7 @@ export type Action = } | { type: 'FETCH_FAILURE'; payload: string } | { type: 'FETCH_UPDATE_CASE_SUCCESS' } - | { type: 'UPDATE_FILTER_OPTIONS'; payload: FilterOptions } + | { type: 'UPDATE_FILTER_OPTIONS'; payload: Partial } | { type: 'UPDATE_QUERY_PARAMS'; payload: Partial } | { type: 'UPDATE_TABLE_SELECTIONS'; payload: Case[] }; @@ -68,7 +68,10 @@ const dataFetchReducer = (state: UseGetCasesState, action: Action): UseGetCasesS case 'UPDATE_FILTER_OPTIONS': return { ...state, - filterOptions: action.payload, + filterOptions: { + ...state.filterOptions, + ...action.payload, + }, }; case 'UPDATE_QUERY_PARAMS': return { @@ -119,8 +122,8 @@ interface UseGetCases extends UseGetCasesState { refetchCasesStatus, }: UpdateCase) => void; refetchCases: (filters: FilterOptions, queryParams: QueryParams) => void; - setFilters: (filters: FilterOptions) => void; - setQueryParams: (queryParams: QueryParams) => void; + setFilters: (filters: Partial) => void; + setQueryParams: (queryParams: Partial) => void; setSelectedCases: (mySelectedCases: Case[]) => void; } @@ -139,11 +142,11 @@ export const useGetCases = (initialQueryParams?: QueryParams): UseGetCases => { dispatch({ type: 'UPDATE_TABLE_SELECTIONS', payload: mySelectedCases }); }, []); - const setQueryParams = useCallback((newQueryParams: QueryParams) => { + const setQueryParams = useCallback((newQueryParams: Partial) => { dispatch({ type: 'UPDATE_QUERY_PARAMS', payload: newQueryParams }); }, []); - const setFilters = useCallback((newFilters: FilterOptions) => { + const setFilters = useCallback((newFilters: Partial) => { dispatch({ type: 'UPDATE_FILTER_OPTIONS', payload: newFilters }); }, []); diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/columns.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/columns.tsx index f757fd33a93a8..0e12f78e29bc2 100644 --- a/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/columns.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/columns.tsx @@ -77,7 +77,7 @@ export const getCasesColumns = ( size="s" /> - {createdBy.fullName ?? createdBy.username ?? ''} + {createdBy.fullName ? createdBy.fullName : createdBy.username ?? ''} ); diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.tsx index 161910bb5498a..b0ff3dbada6c9 100644 --- a/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.tsx @@ -254,11 +254,11 @@ export const AllCases = React.memo(({ userCanCrud }) => { const onFilterChangedCallback = useCallback( (newFilterOptions: Partial) => { if (newFilterOptions.status && newFilterOptions.status === 'closed') { - setQueryParams({ ...queryParams, sortField: SortFieldCase.closedAt }); + setQueryParams({ sortField: SortFieldCase.closedAt }); } else if (newFilterOptions.status && newFilterOptions.status === 'open') { - setQueryParams({ ...queryParams, sortField: SortFieldCase.createdAt }); + setQueryParams({ sortField: SortFieldCase.createdAt }); } - setFilters({ ...filterOptions, ...newFilterOptions }); + setFilters(newFilterOptions); }, [filterOptions, queryParams] ); diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/use_push_to_service/index.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/use_push_to_service/index.tsx index aeb694e52b7fa..4f370ec978906 100644 --- a/x-pack/legacy/plugins/siem/public/pages/case/components/use_push_to_service/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/use_push_to_service/index.tsx @@ -74,7 +74,11 @@ export const usePushToService = ({ if (actionLicense != null && !actionLicense.enabledInLicense) { errors = [...errors, getLicenseError()]; } - if (connector == null && !loadingCaseConfigure && !loadingLicense) { + if ( + (connector == null || (connector != null && connector.connectorId === 'none')) && + !loadingCaseConfigure && + !loadingLicense + ) { errors = [ ...errors, { diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/user_action_tree/user_action_item.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/user_action_tree/user_action_item.tsx index 89b94d98f91db..bcb4edd6129a6 100644 --- a/x-pack/legacy/plugins/siem/public/pages/case/components/user_action_tree/user_action_item.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/user_action_tree/user_action_item.tsx @@ -134,8 +134,8 @@ export const UserActionItem = ({ - {(fullName && fullName.length > 0) || username.length > 0 ? ( - + {(fullName && fullName.length > 0) || (username && username.length > 0) ? ( + 0 ? fullName : username ?? ''} /> ) : ( )} diff --git a/x-pack/plugins/case/server/routes/api/cases/find_cases.ts b/x-pack/plugins/case/server/routes/api/cases/find_cases.ts index e7b2044f2badf..b2716749e9749 100644 --- a/x-pack/plugins/case/server/routes/api/cases/find_cases.ts +++ b/x-pack/plugins/case/server/routes/api/cases/find_cases.ts @@ -31,9 +31,10 @@ const buildFilter = ( ): string => filters != null && filters.length > 0 ? Array.isArray(filters) - ? filters + ? // Be aware of the surrounding parenthesis (as string inside literal) around filters. + `(${filters .map(filter => `${CASE_SAVED_OBJECT}.attributes.${field}: ${filter}`) - ?.join(` ${operator} `) + ?.join(` ${operator} `)})` : `${CASE_SAVED_OBJECT}.attributes.${field}: ${filters}` : '';