Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.7] [SIEM] CASES Bugs BC2 (#62170) #62232

Merged
merged 1 commit into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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