From 60f3df5a67377966f799010db43c08207ab3d9db Mon Sep 17 00:00:00 2001 From: Georgiana-Andreea Onoleata Date: Tue, 29 Oct 2024 13:26:20 +0200 Subject: [PATCH 1/9] Allow users to push to external service when the case is closed --- .../cases/public/components/use_push_to_service/index.tsx | 6 ------ x-pack/plugins/cases/server/client/cases/push.ts | 6 ------ 2 files changed, 12 deletions(-) diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx index 63a016964651e..349715b620ba3 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx @@ -44,7 +44,6 @@ export interface ReturnUsePushToService { export const usePushToService = ({ caseId, - caseStatus, caseConnectors, connector, isValidConnector, @@ -108,14 +107,9 @@ export const usePushToService = ({ return [getDeletedConnectorError()]; } - if (caseStatus === CaseStatuses.closed) { - return [getCaseClosedInfo()]; - } - return errors; }, [ actionLicense, - caseStatus, connector.id, hasLicenseError, isValidConnector, diff --git a/x-pack/plugins/cases/server/client/cases/push.ts b/x-pack/plugins/cases/server/client/cases/push.ts index 85d853f825907..6d4561c7b5119 100644 --- a/x-pack/plugins/cases/server/client/cases/push.ts +++ b/x-pack/plugins/cases/server/client/cases/push.ts @@ -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); From 0a6802026885c0c1bbfba1887bcc4963f954c88c Mon Sep 17 00:00:00 2001 From: Georgiana-Andreea Onoleata Date: Wed, 30 Oct 2024 10:20:13 +0200 Subject: [PATCH 2/9] removed unnecessary test and fixed the failing one --- .../use_push_to_service/index.test.tsx | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx index fccca04bb278f..a984cf442cd3c 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx @@ -182,27 +182,6 @@ describe('usePushToService', () => { expect(result.current.hasErrorMessages).toBe(true); }); - it('Displays message when case is closed', async () => { - const { result } = renderHook< - React.PropsWithChildren, - ReturnUsePushToService - >( - () => - usePushToService({ - ...defaultArgs, - caseStatus: CaseStatuses.closed, - }), - { - wrapper: ({ children }) => {children}, - } - ); - - 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, @@ -460,7 +439,7 @@ describe('usePushToService', () => { const { result } = renderHook< React.PropsWithChildren, ReturnUsePushToService - >(() => usePushToService({ ...defaultArgs, caseStatus: CaseStatuses.closed }), { + >(() => usePushToService({ ...defaultArgs, isValidConnector: false }), { wrapper: ({ children }) => {children}, }); From 95c98d11b0eff3701cc0e4726521c4a25cc0e336 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:06:11 +0000 Subject: [PATCH 3/9] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../cases/public/components/use_push_to_service/index.test.tsx | 1 - .../cases/public/components/use_push_to_service/index.tsx | 2 -- 2 files changed, 3 deletions(-) diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx index a984cf442cd3c..75c2694f89479 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx @@ -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'; diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx index 349715b620ba3..465e48bddade7 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx @@ -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'; From 08aaae5447ca09578a0456f6178d5a7d2669300f Mon Sep 17 00:00:00 2001 From: Georgiana-Andreea Onoleata Date: Wed, 30 Oct 2024 16:08:23 +0200 Subject: [PATCH 4/9] removed test --- .../tests/trial/cases/push_case.ts | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts index a07d4aa2d24e1..f1195806a1559 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts @@ -488,33 +488,6 @@ export default ({ getService }: FtrProviderContext): void => { }); }); - it('unhappy path = 409s when case is closed', async () => { - const { postedCase, connector } = await createCaseWithConnector({ - supertest, - serviceNowSimulatorURL, - actionsRemover, - }); - await updateCase({ - supertest, - params: { - cases: [ - { - id: postedCase.id, - version: postedCase.version, - status: CaseStatuses.closed, - }, - ], - }, - }); - - await pushCase({ - supertest, - caseId: postedCase.id, - connectorId: connector.id, - expectedHttpCode: 409, - }); - }); - // FLAKY: https://github.com/elastic/kibana/issues/157588 describe.skip('user profile uid', () => { let headers: Record; From 65d993d06715bb3828cdc5cef69c19a6add813a2 Mon Sep 17 00:00:00 2001 From: Georgiana-Andreea Onoleata Date: Wed, 30 Oct 2024 16:23:45 +0200 Subject: [PATCH 5/9] added test - push a closed case --- .../tests/trial/cases/push_case.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts index f1195806a1559..da1416cbb9430 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts @@ -488,6 +488,33 @@ export default ({ getService }: FtrProviderContext): void => { }); }); + it('should push a closed case', async () => { + const { postedCase, connector } = await createCaseWithConnector({ + supertest, + serviceNowSimulatorURL, + actionsRemover, + }); + await updateCase({ + supertest, + params: { + cases: [ + { + id: postedCase.id, + version: postedCase.version, + status: CaseStatuses.closed, + }, + ], + }, + }); + + await pushCase({ + supertest, + caseId: postedCase.id, + connectorId: connector.id, + expectedHttpCode: 200, + }); + }); + // FLAKY: https://github.com/elastic/kibana/issues/157588 describe.skip('user profile uid', () => { let headers: Record; From c67ccfdea2ab2c680e08171f6ba397d042b89e6c Mon Sep 17 00:00:00 2001 From: Georgiana-Andreea Onoleata Date: Mon, 4 Nov 2024 11:09:09 +0200 Subject: [PATCH 6/9] added test -> checks if the closed case is pushed --- .../use_push_to_service/index.test.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx index 75c2694f89479..9e639a1adbcff 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx @@ -7,6 +7,7 @@ import React from 'react'; import { renderHook, act } from '@testing-library/react-hooks'; +import { screen } from '@testing-library/react'; import type { ReturnUsePushToService, UsePushToService } from '.'; import { usePushToService } from '.'; @@ -181,6 +182,22 @@ describe('usePushToService', () => { expect(result.current.hasErrorMessages).toBe(true); }); + it('Successfully pushed a closed case', () => { + const { result } = renderHook< + React.PropsWithChildren, + ReturnUsePushToService + >( + () => + usePushToService({ + ...defaultArgs, + caseStatus: CaseStatuses.closed, + }), + { + wrapper: ({ children }) => {children}, + } + ); + expect(result.current.hasBeenPushed).toBe(true); + }); it('should not call pushCaseToExternalService when the selected connector is none', async () => { const { result } = renderHook< React.PropsWithChildren, From 75780c2e7b0f3d957715202209aeef9c7d7e0275 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 4 Nov 2024 09:30:21 +0000 Subject: [PATCH 7/9] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../cases/public/components/use_push_to_service/index.test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx index 9e639a1adbcff..e95fa303bcff9 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx @@ -7,7 +7,6 @@ import React from 'react'; import { renderHook, act } from '@testing-library/react-hooks'; -import { screen } from '@testing-library/react'; import type { ReturnUsePushToService, UsePushToService } from '.'; import { usePushToService } from '.'; From ad6d67496d024751e5cdd39815380cbfb34956d9 Mon Sep 17 00:00:00 2001 From: Georgiana-Andreea Onoleata Date: Mon, 4 Nov 2024 13:55:03 +0200 Subject: [PATCH 8/9] added fix for test --- .../cases/public/components/use_push_to_service/index.test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx index 9e639a1adbcff..e95fa303bcff9 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx @@ -7,7 +7,6 @@ import React from 'react'; import { renderHook, act } from '@testing-library/react-hooks'; -import { screen } from '@testing-library/react'; import type { ReturnUsePushToService, UsePushToService } from '.'; import { usePushToService } from '.'; From 54c39a4537f78e14f73c7897dfe8a3aa48aab34b Mon Sep 17 00:00:00 2001 From: Georgiana-Andreea Onoleata Date: Tue, 5 Nov 2024 12:29:49 +0200 Subject: [PATCH 9/9] temp: removed test --- .../use_push_to_service/index.test.tsx | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx index e95fa303bcff9..75c2694f89479 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx @@ -181,22 +181,6 @@ describe('usePushToService', () => { expect(result.current.hasErrorMessages).toBe(true); }); - it('Successfully pushed a closed case', () => { - const { result } = renderHook< - React.PropsWithChildren, - ReturnUsePushToService - >( - () => - usePushToService({ - ...defaultArgs, - caseStatus: CaseStatuses.closed, - }), - { - wrapper: ({ children }) => {children}, - } - ); - expect(result.current.hasBeenPushed).toBe(true); - }); it('should not call pushCaseToExternalService when the selected connector is none', async () => { const { result } = renderHook< React.PropsWithChildren,