diff --git a/x-pack/plugins/case/server/client/cases/get.ts b/x-pack/plugins/case/server/client/cases/get.ts index 55c8987778d023..c1901ccaae511c 100644 --- a/x-pack/plugins/case/server/client/cases/get.ts +++ b/x-pack/plugins/case/server/client/cases/get.ts @@ -13,12 +13,10 @@ export const get = ({ savedObjectsClient, caseService }: CaseClientFactoryArgume id, includeComments = false, }: CaseClientGet): Promise => { - const [theCase] = await Promise.all([ - caseService.getCase({ - client: savedObjectsClient, - caseId: id, - }), - ]); + const theCase = await caseService.getCase({ + client: savedObjectsClient, + caseId: id, + }); if (!includeComments) { return CaseResponseRt.encode( diff --git a/x-pack/plugins/case/server/client/cases/push.ts b/x-pack/plugins/case/server/client/cases/push.ts index 6bfde109b44585..dca4c0bba74d33 100644 --- a/x-pack/plugins/case/server/client/cases/push.ts +++ b/x-pack/plugins/case/server/client/cases/push.ts @@ -37,6 +37,7 @@ export const push = ({ /* Start of push to external service */ const theCase = await caseClient.get({ id: caseId, includeComments: true }); + // We need to change the logic when we support subcases if (theCase.status === CaseStatuses.closed) { throw Boom.conflict( `This case ${theCase.title} is closed. You can not pushed if the case is closed.` diff --git a/x-pack/plugins/case/server/client/cases/utils.ts b/x-pack/plugins/case/server/client/cases/utils.ts index 055520861f223e..b0489f00905a3e 100644 --- a/x-pack/plugins/case/server/client/cases/utils.ts +++ b/x-pack/plugins/case/server/client/cases/utils.ts @@ -24,7 +24,6 @@ import { import { ActionsClient } from '../../../../actions/server'; import { externalServiceFormatters, FormatterConnectorTypes } from '../../connectors'; import { CaseClientGetAlertsResponse } from '../../client/alerts/types'; -import { isUserContext } from '../../routes/api/utils'; import { BasicParams, EntityInformation, @@ -300,14 +299,23 @@ export const isCommentAlertType = ( export const getCommentContextFromAttributes = ( attributes: CommentAttributes -): CommentRequestUserType | CommentRequestAlertType => - isUserContext(attributes) - ? { +): CommentRequestUserType | CommentRequestAlertType => { + switch (attributes.type) { + case CommentType.user: + return { type: CommentType.user, comment: attributes.comment, - } - : { + }; + case CommentType.alert: + return { type: CommentType.alert, alertId: attributes.alertId, index: attributes.index, }; + default: + return { + type: CommentType.user, + comment: '', + }; + } +}; diff --git a/x-pack/plugins/case/server/connectors/jira/external_service_formatter.ts b/x-pack/plugins/case/server/connectors/jira/external_service_formatter.ts index c5c65d8648102b..74376d295fea5a 100644 --- a/x-pack/plugins/case/server/connectors/jira/external_service_formatter.ts +++ b/x-pack/plugins/case/server/connectors/jira/external_service_formatter.ts @@ -12,7 +12,7 @@ interface ExternalServiceParams extends JiraFieldsType { labels: string[]; } -const format: ExternalServiceFormatter['format'] = async (theCase) => { +const format: ExternalServiceFormatter['format'] = (theCase) => { const { priority = null, issueType = null, parent = null } = (theCase.connector.fields as ConnectorJiraTypeFields['fields']) ?? {}; return { diff --git a/x-pack/plugins/case/server/connectors/resilient/external_service_formatter.ts b/x-pack/plugins/case/server/connectors/resilient/external_service_formatter.ts index e1d862de88f16d..76554dce32797e 100644 --- a/x-pack/plugins/case/server/connectors/resilient/external_service_formatter.ts +++ b/x-pack/plugins/case/server/connectors/resilient/external_service_formatter.ts @@ -8,7 +8,7 @@ import { ResilientFieldsType, ConnectorResillientTypeFields } from '../../../common/api'; import { ExternalServiceFormatter } from '../types'; -const format: ExternalServiceFormatter['format'] = async (theCase) => { +const format: ExternalServiceFormatter['format'] = (theCase) => { const { incidentTypes = null, severityCode = null } = (theCase.connector.fields as ConnectorResillientTypeFields['fields']) ?? {}; return { incidentTypes, severityCode }; diff --git a/x-pack/plugins/case/server/connectors/servicenow/itsm_formatter.ts b/x-pack/plugins/case/server/connectors/servicenow/itsm_formatter.ts index f05508b9b673ca..60faa82a9e3fa3 100644 --- a/x-pack/plugins/case/server/connectors/servicenow/itsm_formatter.ts +++ b/x-pack/plugins/case/server/connectors/servicenow/itsm_formatter.ts @@ -8,7 +8,7 @@ import { ServiceNowITSMFieldsType, ConnectorServiceNowITSMTypeFields } from '../../../common/api'; import { ExternalServiceFormatter } from '../types'; -const format: ExternalServiceFormatter['format'] = async (theCase) => { +const format: ExternalServiceFormatter['format'] = (theCase) => { const { severity = null, urgency = null, impact = null } = (theCase.connector.fields as ConnectorServiceNowITSMTypeFields['fields']) ?? {}; return { severity, urgency, impact }; diff --git a/x-pack/plugins/case/server/connectors/servicenow/sir_formatter.ts b/x-pack/plugins/case/server/connectors/servicenow/sir_formatter.ts index 4e244f9717d76e..84e261432eb1f1 100644 --- a/x-pack/plugins/case/server/connectors/servicenow/sir_formatter.ts +++ b/x-pack/plugins/case/server/connectors/servicenow/sir_formatter.ts @@ -24,10 +24,7 @@ type AlertFieldMappingAndValues = Record< { alertPath: string; values: Set; sirFieldKey: string } >; -const format: ExternalServiceFormatter['format'] = async ( - theCase, - alerts -) => { +const format: ExternalServiceFormatter['format'] = (theCase, alerts) => { const { destIp = null, sourceIp = null, diff --git a/x-pack/plugins/case/server/connectors/types.ts b/x-pack/plugins/case/server/connectors/types.ts index 1c6c857a9524c2..8e7eb91ad2dc66 100644 --- a/x-pack/plugins/case/server/connectors/types.ts +++ b/x-pack/plugins/case/server/connectors/types.ts @@ -46,10 +46,7 @@ export interface RegisterConnectorsArgs extends GetActionTypeParams { export type FormatterConnectorTypes = Exclude; export interface ExternalServiceFormatter { - format: ( - theCase: CaseResponse, - alerts: CaseClientGetAlertsResponse - ) => Promise; + format: (theCase: CaseResponse, alerts: CaseClientGetAlertsResponse) => TExternalServiceParams; } export type ExternalServiceFormatterMapper = {