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

[ResponseOps][Cases]Allow users to push to external service when the case is closed #198146

Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { usePushToService } from '.';
import { noPushCasesPermissions, readCasesPermissions, TestProviders } from '../../common/mock';
import { usePostPushToService } from '../../containers/use_post_push_to_service';
import { actionLicenses } from '../../containers/mock';
import { CLOSED_CASE_PUSH_ERROR_ID } from './callout/types';
import { useGetActionLicense } from '../../containers/use_get_action_license';
import { getCaseConnectorsMockResponse } from '../../common/mock/connectors';
import { useRefreshCaseViewPage } from '../case_view/use_on_refresh_case_view_page';
Expand Down Expand Up @@ -182,27 +181,6 @@ describe('usePushToService', () => {
expect(result.current.hasErrorMessages).toBe(true);
});

it('Displays message when case is closed', async () => {
js-jankisalvi marked this conversation as resolved.
Show resolved Hide resolved
const { result } = renderHook<
React.PropsWithChildren<UsePushToService>,
ReturnUsePushToService
>(
() =>
usePushToService({
...defaultArgs,
caseStatus: CaseStatuses.closed,
}),
{
wrapper: ({ children }) => <TestProviders> {children}</TestProviders>,
}
);

const errorsMsg = result.current.errorsMsg;
expect(errorsMsg).toHaveLength(1);
expect(errorsMsg[0].id).toEqual(CLOSED_CASE_PUSH_ERROR_ID);
expect(result.current.hasErrorMessages).toBe(true);
});

it('should not call pushCaseToExternalService when the selected connector is none', async () => {
const { result } = renderHook<
React.PropsWithChildren<UsePushToService>,
Expand Down Expand Up @@ -460,7 +438,7 @@ describe('usePushToService', () => {
const { result } = renderHook<
React.PropsWithChildren<UsePushToService>,
ReturnUsePushToService
>(() => usePushToService({ ...defaultArgs, caseStatus: CaseStatuses.closed }), {
>(() => usePushToService({ ...defaultArgs, isValidConnector: false }), {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'hasErrorMessages=true if there are error messages' so is isValidConnector: false just a different way of throwing an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought I can replace the caseStatus: CaseStatuses.closed with isValidConnector: false just to be able to throw an error in this case.

wrapper: ({ children }) => <TestProviders> {children}</TestProviders>,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import {
getKibanaConfigError,
getConnectorMissingInfo,
getDeletedConnectorError,
getCaseClosedInfo,
} from './helpers';
import type { CaseConnector } from '../../../common/types/domain';
import { CaseStatuses } from '../../../common/types/domain';
import type { ErrorMessage } from './callout/types';
import { useRefreshCaseViewPage } from '../case_view/use_on_refresh_case_view_page';
import { useGetActionLicense } from '../../containers/use_get_action_license';
Expand Down Expand Up @@ -44,7 +42,6 @@ export interface ReturnUsePushToService {

export const usePushToService = ({
caseId,
caseStatus,
caseConnectors,
connector,
isValidConnector,
Expand Down Expand Up @@ -108,14 +105,9 @@ export const usePushToService = ({
return [getDeletedConnectorError()];
}

if (caseStatus === CaseStatuses.closed) {
return [getCaseClosedInfo()];
}

return errors;
}, [
actionLicense,
caseStatus,
connector.id,
hasLicenseError,
isValidConnector,
Expand Down
6 changes: 0 additions & 6 deletions x-pack/plugins/cases/server/client/cases/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ export const push = async (
operation: Operations.pushCase,
});

if (theCase?.status === CaseStatuses.closed) {
throw Boom.conflict(
`The ${theCase.title} case is closed. Pushing a closed case is not allowed.`
);
}

const alertsInfo = getAlertInfoFromComments(theCase?.comments);
const alerts = await getAlerts(alertsInfo, clientArgs);
const profiles = await getProfiles(theCase, securityStartPlugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export default ({ getService }: FtrProviderContext): void => {
});
});

it('unhappy path = 409s when case is closed', async () => {
it('should push a closed case', async () => {
const { postedCase, connector } = await createCaseWithConnector({
supertest,
serviceNowSimulatorURL,
Expand All @@ -511,7 +511,7 @@ export default ({ getService }: FtrProviderContext): void => {
supertest,
caseId: postedCase.id,
connectorId: connector.id,
expectedHttpCode: 409,
expectedHttpCode: 200,
});
});

Expand Down