Skip to content

Commit

Permalink
[SIEM] CASES Bugs BC2 (#62170)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
XavierM and cnasikas authored Apr 1, 2020
1 parent 3fdddea commit b1a39ce
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 24 deletions.
7 changes: 7 additions & 0 deletions x-pack/legacy/plugins/siem/public/containers/case/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import {
decodeServiceConnectorCaseResponse,
} from './utils';

import * as i18n from './translations';

export const getCase = async (
caseId: string,
includeComments: boolean = true,
Expand Down Expand Up @@ -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);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -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<FilterOptions> }
| { type: 'UPDATE_QUERY_PARAMS'; payload: Partial<QueryParams> }
| { type: 'UPDATE_TABLE_SELECTIONS'; payload: Case[] };

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<FilterOptions>) => void;
setQueryParams: (queryParams: Partial<QueryParams>) => void;
setSelectedCases: (mySelectedCases: Case[]) => void;
}

Expand All @@ -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<QueryParams>) => {
dispatch({ type: 'UPDATE_QUERY_PARAMS', payload: newQueryParams });
}, []);

const setFilters = useCallback((newFilters: FilterOptions) => {
const setFilters = useCallback((newFilters: Partial<FilterOptions>) => {
dispatch({ type: 'UPDATE_FILTER_OPTIONS', payload: newFilters });
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const getCasesColumns = (
size="s"
/>
<Spacer data-test-subj="case-table-column-createdBy">
{createdBy.fullName ?? createdBy.username ?? ''}
{createdBy.fullName ? createdBy.fullName : createdBy.username ?? ''}
</Spacer>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ export const AllCases = React.memo<AllCasesProps>(({ userCanCrud }) => {
const onFilterChangedCallback = useCallback(
(newFilterOptions: Partial<FilterOptions>) => {
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]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ export const UserActionItem = ({
<EuiFlexItem>
<EuiFlexGroup gutterSize={'none'}>
<EuiFlexItem data-test-subj={`user-action-${id}-avatar`} grow={false}>
{(fullName && fullName.length > 0) || username.length > 0 ? (
<UserActionAvatar name={fullName ?? username} />
{(fullName && fullName.length > 0) || (username && username.length > 0) ? (
<UserActionAvatar name={fullName && fullName.length > 0 ? fullName : username ?? ''} />
) : (
<EuiLoadingSpinner className="userAction_loadingAvatar" />
)}
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/case/server/routes/api/cases/find_cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
: '';

Expand Down

0 comments on commit b1a39ce

Please sign in to comment.