diff --git a/x-pack/plugins/cases/server/common/types/attachments.ts b/x-pack/plugins/cases/server/common/types/attachments.ts new file mode 100644 index 0000000000000..55b9990c5fb12 --- /dev/null +++ b/x-pack/plugins/cases/server/common/types/attachments.ts @@ -0,0 +1,48 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { JsonValue } from '@kbn/utility-types'; +import type { User } from './user'; + +interface AttachmentCommonPersistedAttributes { + created_at: string; + created_by: User; + owner: string; + pushed_at: string | null; + pushed_by: User | null; + updated_at: string | null; + updated_by: User | null; +} + +export interface AttachmentRequestAttributes { + type: string; + alertId?: string | string[]; + index?: string | string[]; + rule?: { + id: string | null; + name: string | null; + }; + comment?: string; + actions?: { + targets: Array<{ + hostname: string; + endpointId: string; + }>; + type: string; + }; + externalReferenceMetadata?: Record | null; + externalReferenceAttachmentTypeId?: string; + externalReferenceStorage?: { + type: string; + soType?: string; + }; + persistableStateAttachmentState?: Record; + persistableStateAttachmentTypeId?: string; +} + +export type AttachmentPersistedAttributes = AttachmentRequestAttributes & + AttachmentCommonPersistedAttributes; diff --git a/x-pack/plugins/cases/server/common/utils.ts b/x-pack/plugins/cases/server/common/utils.ts index 1554d5a64f20b..b04c9fd596503 100644 --- a/x-pack/plugins/cases/server/common/utils.ts +++ b/x-pack/plugins/cases/server/common/utils.ts @@ -34,7 +34,6 @@ import type { CommentRequest, CommentRequestActionsType, CommentRequestAlertType, - CommentRequestExternalReferenceSOType, CommentRequestUserType, CommentResponse, CommentsResponse, @@ -45,7 +44,6 @@ import { CaseStatuses, CommentType, ConnectorTypes, - ExternalReferenceStorageType, ExternalReferenceSORt, FileAttachmentMetadataRt, } from '../../common/api'; @@ -254,18 +252,6 @@ export const isCommentRequestTypeAlert = ( return context.type === CommentType.alert; }; -/** - * A type narrowing function for external reference so attachments. - */ -export const isCommentRequestTypeExternalReferenceSO = ( - context: Partial -): context is CommentRequestExternalReferenceSOType => { - return ( - context.type === CommentType.externalReference && - context.externalReferenceStorage?.type === ExternalReferenceStorageType.savedObject - ); -}; - /** * A type narrowing function for file attachments. */ diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/comments.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/comments.ts index b3978b6e12ef6..02afa01bf49c3 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/comments.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/comments.ts @@ -17,7 +17,6 @@ import type { } from '@kbn/core/server'; import { mergeSavedObjectMigrationMaps } from '@kbn/core/server'; import type { LensServerPluginSetup } from '@kbn/lens-plugin/server'; -import type { CommentAttributes } from '../../../common/api'; import { CommentType } from '../../../common/api'; import type { LensMarkdownNode, MarkdownNode } from '../../../common/utils/markdown_plugins/utils'; import { @@ -32,6 +31,7 @@ import { GENERATED_ALERT, SUB_CASE_SAVED_OBJECT } from './constants'; import type { PersistableStateAttachmentTypeRegistry } from '../../attachment_framework/persistable_state_registry'; import { getAllPersistableAttachmentMigrations } from './get_all_persistable_attachment_migrations'; import type { PersistableStateAttachmentState } from '../../attachment_framework/types'; +import type { AttachmentPersistedAttributes } from '../../common/types/attachments'; interface UnsanitizedComment { comment: string; @@ -71,7 +71,7 @@ export const createCommentsMigrations = ( const persistableStateAttachmentMigrations = mapValues< MigrateFunctionsObject, - SavedObjectMigrationFn + SavedObjectMigrationFn >( getAllPersistableAttachmentMigrations(migrationDeps.persistableStateAttachmentTypeRegistry), migratePersistableStateAttachments @@ -134,8 +134,10 @@ export const createCommentsMigrations = ( }; export const migratePersistableStateAttachments = - (migrate: MigrateFunction): SavedObjectMigrationFn => - (doc: SavedObjectUnsanitizedDoc) => { + ( + migrate: MigrateFunction + ): SavedObjectMigrationFn => + (doc: SavedObjectUnsanitizedDoc) => { if (doc.attributes.type !== CommentType.persistableState) { return doc; } diff --git a/x-pack/plugins/cases/server/services/attachments/index.ts b/x-pack/plugins/cases/server/services/attachments/index.ts index bde31a375ec72..e76b93ce0e5b9 100644 --- a/x-pack/plugins/cases/server/services/attachments/index.ts +++ b/x-pack/plugins/cases/server/services/attachments/index.ts @@ -7,20 +7,14 @@ import type { SavedObject, - SavedObjectReference, SavedObjectsBulkResponse, SavedObjectsBulkUpdateResponse, SavedObjectsFindResponse, - SavedObjectsUpdateOptions, SavedObjectsUpdateResponse, } from '@kbn/core/server'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -import type { - CommentAttributes as AttachmentAttributes, - CommentAttributesWithoutRefs as AttachmentAttributesWithoutRefs, - CommentPatchAttributes as AttachmentPatchAttributes, -} from '../../../common/api'; +import type { CommentAttributes as AttachmentAttributes } from '../../../common/api'; import { CommentType } from '../../../common/api'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT } from '../../../common/constants'; import { buildFilter, combineFilters } from '../../client/utils'; @@ -32,50 +26,19 @@ import { injectAttachmentSOAttributesFromRefsForPatch, } from '../so_references'; import type { SavedObjectFindOptionsKueryNode } from '../../common/types'; -import type { IndexRefresh } from '../types'; -import type { AttachedToCaseArgs, ServiceContext } from './types'; +import type { + AlertsAttachedToCaseArgs, + AttachmentsAttachedToCaseArgs, + BulkCreateAttachments, + BulkUpdateAttachmentArgs, + CountActionsAttachedToCaseArgs, + CreateAttachmentArgs, + DeleteAttachmentArgs, + ServiceContext, + UpdateAttachmentArgs, +} from './types'; import { AttachmentGetter } from './operations/get'; - -type AlertsAttachedToCaseArgs = AttachedToCaseArgs; - -interface AttachmentsAttachedToCaseArgs extends AttachedToCaseArgs { - attachmentType: CommentType; - aggregations: Record; -} - -interface CountActionsAttachedToCaseArgs extends AttachedToCaseArgs { - aggregations: Record; -} - -interface DeleteAttachmentArgs extends IndexRefresh { - attachmentIds: string[]; -} - -interface CreateAttachmentArgs extends IndexRefresh { - attributes: AttachmentAttributes; - references: SavedObjectReference[]; - id: string; -} - -interface BulkCreateAttachments extends IndexRefresh { - attachments: Array<{ - attributes: AttachmentAttributes; - references: SavedObjectReference[]; - id: string; - }>; -} - -interface UpdateArgs { - attachmentId: string; - updatedAttributes: AttachmentPatchAttributes; - options?: Omit, 'upsert'>; -} - -export type UpdateAttachmentArgs = UpdateArgs; - -interface BulkUpdateAttachmentArgs extends IndexRefresh { - comments: UpdateArgs[]; -} +import type { AttachmentPersistedAttributes } from '../../common/types/attachments'; export class AttachmentService { private readonly _getter: AttachmentGetter; @@ -136,10 +99,7 @@ export class AttachmentService { const combinedFilter = combineFilters([attachmentFilter, filter]); - const response = await this.context.unsecuredSavedObjectsClient.find< - AttachmentAttributes, - Agg - >({ + const response = await this.context.unsecuredSavedObjectsClient.find({ type: CASE_COMMENT_SAVED_OBJECT, hasReference: { type: CASE_SAVED_OBJECT, id: caseId }, page: 1, @@ -207,7 +167,7 @@ export class AttachmentService { ); const attachment = - await this.context.unsecuredSavedObjectsClient.create( + await this.context.unsecuredSavedObjectsClient.create( CASE_COMMENT_SAVED_OBJECT, extractedAttributes, { @@ -234,7 +194,7 @@ export class AttachmentService { try { this.context.log.debug(`Attempting to bulk create attachments`); const res = - await this.context.unsecuredSavedObjectsClient.bulkCreate( + await this.context.unsecuredSavedObjectsClient.bulkCreate( attachments.map((attachment) => { const { attributes: extractedAttributes, references: extractedReferences } = extractAttachmentSORefsFromAttributes( @@ -288,7 +248,7 @@ export class AttachmentService { const shouldUpdateRefs = extractedReferences.length > 0 || didDeleteOperation; const res = - await this.context.unsecuredSavedObjectsClient.update( + await this.context.unsecuredSavedObjectsClient.update( CASE_COMMENT_SAVED_OBJECT, attachmentId, extractedAttributes, @@ -325,7 +285,7 @@ export class AttachmentService { ); const res = - await this.context.unsecuredSavedObjectsClient.bulkUpdate( + await this.context.unsecuredSavedObjectsClient.bulkUpdate( comments.map((c) => { const { attributes: extractedAttributes, @@ -380,7 +340,7 @@ export class AttachmentService { try { this.context.log.debug(`Attempting to find comments`); const res = - await this.context.unsecuredSavedObjectsClient.find({ + await this.context.unsecuredSavedObjectsClient.find({ sortField: defaultSortField, ...options, type: CASE_COMMENT_SAVED_OBJECT, diff --git a/x-pack/plugins/cases/server/services/attachments/operations/get.ts b/x-pack/plugins/cases/server/services/attachments/operations/get.ts index 3db7059b3977b..4aa5c65ebdcc1 100644 --- a/x-pack/plugins/cases/server/services/attachments/operations/get.ts +++ b/x-pack/plugins/cases/server/services/attachments/operations/get.ts @@ -8,6 +8,7 @@ import type { SavedObject } from '@kbn/core/server'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { FILE_SO_TYPE } from '@kbn/files-plugin/common'; +import type { AttachmentPersistedAttributes } from '../../../common/types/attachments'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT, @@ -19,13 +20,12 @@ import type { AttachmentTotals, AttributesTypeAlerts, CommentAttributes as AttachmentAttributes, - CommentAttributesWithoutRefs as AttachmentAttributesWithoutRefs, - CommentAttributes, } from '../../../../common/api'; import { CommentType } from '../../../../common/api'; import type { - AttachedToCaseArgs, + AlertIdsAggsResult, BulkOptionalAttributes, + GetAllAlertsAttachToCaseArgs, GetAttachmentArgs, ServiceContext, } from '../types'; @@ -37,29 +37,19 @@ import { partitionByCaseAssociation } from '../../../common/partitioning'; import type { AttachmentSavedObject } from '../../../common/types'; import { getCaseReferenceId } from '../../../common/references'; -type GetAllAlertsAttachToCaseArgs = AttachedToCaseArgs; - -interface AlertIdsAggsResult { - alertIds: { - buckets: Array<{ - key: string; - }>; - }; -} - export class AttachmentGetter { constructor(private readonly context: ServiceContext) {} public async bulkGet( attachmentIds: string[] - ): Promise> { + ): Promise> { try { this.context.log.debug( `Attempting to retrieve attachments with ids: ${attachmentIds.join()}` ); const response = - await this.context.unsecuredSavedObjectsClient.bulkGet( + await this.context.unsecuredSavedObjectsClient.bulkGet( attachmentIds.map((id) => ({ id, type: CASE_COMMENT_SAVED_OBJECT })) ); @@ -85,7 +75,9 @@ export class AttachmentGetter { `Attempting to retrieve attachments associated with cases: [${caseIds}]` ); - const finder = this.context.unsecuredSavedObjectsClient.createPointInTimeFinder({ + // We are intentionally not adding the type here because we only want to interact with the id and this function + // should not use the attributes + const finder = this.context.unsecuredSavedObjectsClient.createPointInTimeFinder({ type: CASE_COMMENT_SAVED_OBJECT, hasReference: caseIds.map((id) => ({ id, type: CASE_SAVED_OBJECT })), sortField: 'created_at', @@ -133,18 +125,24 @@ export class AttachmentGetter { const combinedFilter = combineFilters([alertsFilter, filter]); const finder = - this.context.unsecuredSavedObjectsClient.createPointInTimeFinder({ - type: CASE_COMMENT_SAVED_OBJECT, - hasReference: { type: CASE_SAVED_OBJECT, id: caseId }, - sortField: 'created_at', - sortOrder: 'asc', - filter: combinedFilter, - perPage: MAX_DOCS_PER_PAGE, - }); + this.context.unsecuredSavedObjectsClient.createPointInTimeFinder( + { + type: CASE_COMMENT_SAVED_OBJECT, + hasReference: { type: CASE_SAVED_OBJECT, id: caseId }, + sortField: 'created_at', + sortOrder: 'asc', + filter: combinedFilter, + perPage: MAX_DOCS_PER_PAGE, + } + ); let result: Array> = []; for await (const userActionSavedObject of finder.find()) { - result = result.concat(userActionSavedObject.saved_objects); + result = result.concat( + // We need a cast here because to limited attachment type conflicts with the expected result even though they + // should be the same + userActionSavedObject.saved_objects as unknown as Array> + ); } return result; @@ -197,11 +195,10 @@ export class AttachmentGetter { }: GetAttachmentArgs): Promise> { try { this.context.log.debug(`Attempting to GET attachment ${attachmentId}`); - const res = - await this.context.unsecuredSavedObjectsClient.get( - CASE_COMMENT_SAVED_OBJECT, - attachmentId - ); + const res = await this.context.unsecuredSavedObjectsClient.get( + CASE_COMMENT_SAVED_OBJECT, + attachmentId + ); return injectAttachmentSOAttributesFromRefs( res, @@ -305,7 +302,7 @@ export class AttachmentGetter { }: { caseId: string; fileIds: string[]; - }): Promise>> { + }): Promise>> { try { this.context.log.debug('Attempting to find file attachments'); @@ -324,7 +321,7 @@ export class AttachmentGetter { * to retrieve them all. */ const finder = - this.context.unsecuredSavedObjectsClient.createPointInTimeFinder( + this.context.unsecuredSavedObjectsClient.createPointInTimeFinder( { type: CASE_COMMENT_SAVED_OBJECT, hasReference: references, @@ -334,7 +331,7 @@ export class AttachmentGetter { } ); - const foundAttachments: Array> = []; + const foundAttachments: Array> = []; for await (const attachmentSavedObjects of finder.find()) { foundAttachments.push( diff --git a/x-pack/plugins/cases/server/services/attachments/types.ts b/x-pack/plugins/cases/server/services/attachments/types.ts index 554ba8afb049b..dbf9075031d83 100644 --- a/x-pack/plugins/cases/server/services/attachments/types.ts +++ b/x-pack/plugins/cases/server/services/attachments/types.ts @@ -5,15 +5,24 @@ * 2.0. */ +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { Logger, SavedObject, + SavedObjectReference, SavedObjectsBulkResponse, SavedObjectsClientContract, + SavedObjectsUpdateOptions, } from '@kbn/core/server'; import type { KueryNode } from '@kbn/es-query'; +import type { CommentType } from '../../../common'; +import type { + CommentAttributes as AttachmentAttributes, + CommentPatchAttributes as AttachmentPatchAttributes, +} from '../../../common/api'; import type { PersistableStateAttachmentTypeRegistry } from '../../attachment_framework/persistable_state_registry'; import type { PartialField } from '../../types'; +import type { IndexRefresh } from '../types'; export interface ServiceContext { log: Logger; @@ -36,3 +45,54 @@ export interface BulkOptionalAttributes extends Omit, 'saved_objects'> { saved_objects: Array>; } + +export type GetAllAlertsAttachToCaseArgs = AttachedToCaseArgs; + +export interface AlertIdsAggsResult { + alertIds: { + buckets: Array<{ + key: string; + }>; + }; +} + +export type AlertsAttachedToCaseArgs = AttachedToCaseArgs; + +export interface AttachmentsAttachedToCaseArgs extends AttachedToCaseArgs { + attachmentType: CommentType; + aggregations: Record; +} + +export interface CountActionsAttachedToCaseArgs extends AttachedToCaseArgs { + aggregations: Record; +} + +export interface DeleteAttachmentArgs extends IndexRefresh { + attachmentIds: string[]; +} + +export interface CreateAttachmentArgs extends IndexRefresh { + attributes: AttachmentAttributes; + references: SavedObjectReference[]; + id: string; +} + +export interface BulkCreateAttachments extends IndexRefresh { + attachments: Array<{ + attributes: AttachmentAttributes; + references: SavedObjectReference[]; + id: string; + }>; +} + +export interface UpdateArgs { + attachmentId: string; + updatedAttributes: AttachmentPatchAttributes; + options?: Omit, 'upsert'>; +} + +export type UpdateAttachmentArgs = UpdateArgs; + +export interface BulkUpdateAttachmentArgs extends IndexRefresh { + comments: UpdateArgs[]; +} diff --git a/x-pack/plugins/cases/server/services/cases/index.ts b/x-pack/plugins/cases/server/services/cases/index.ts index 8ff9828343cb5..93c6d610d5539 100644 --- a/x-pack/plugins/cases/server/services/cases/index.ts +++ b/x-pack/plugins/cases/server/services/cases/index.ts @@ -108,7 +108,7 @@ export class CasesService { alertId, filter, }: GetCaseIdsByAlertIdArgs): Promise< - SavedObjectsFindResponse + SavedObjectsFindResponse<{ owner: string }, GetCaseIdsByAlertIdAggs> > { try { this.log.debug(`Attempting to GET all cases for alert id ${alertId}`); @@ -118,7 +118,7 @@ export class CasesService { ]); const response = await this.unsecuredSavedObjectsClient.find< - CommentAttributes, + { owner: string }, GetCaseIdsByAlertIdAggs >({ type: CASE_COMMENT_SAVED_OBJECT, @@ -140,7 +140,7 @@ export class CasesService { * Extracts the case IDs from the alert aggregation */ public static getCaseIDsFromAlertAggs( - result: SavedObjectsFindResponse + result: SavedObjectsFindResponse ): string[] { return result.aggregations?.references.caseIds.buckets.map((b) => b.key) ?? []; } @@ -338,6 +338,8 @@ export class CasesService { } } + // TODO: This should probably be moved into the client since it is after the transform has + // occurred within the attachment service private async getAllComments({ id, options, @@ -367,6 +369,8 @@ export class CasesService { } } + // TODO: This should probably be moved into the client since it is after the transform has + // occurred within the attachment service /** * Default behavior is to retrieve all comments that adhere to a given filter (if one is included). * to override this pass in the either the page or perPage options. diff --git a/x-pack/plugins/cases/server/services/so_references.ts b/x-pack/plugins/cases/server/services/so_references.ts index f85c4cab1829d..8a3cc747c752a 100644 --- a/x-pack/plugins/cases/server/services/so_references.ts +++ b/x-pack/plugins/cases/server/services/so_references.ts @@ -5,15 +5,16 @@ * 2.0. */ -import type { SavedObjectsUpdateResponse } from '@kbn/core/server'; -import type { SavedObject, SavedObjectReference } from '@kbn/core/types'; +import type { + SavedObjectsUpdateResponse, + SavedObject, + SavedObjectReference, +} from '@kbn/core/server'; import { isEqual, uniqWith } from 'lodash'; import type { CommentAttributesNoSO, - CommentRequest, CommentAttributes, CommentPatchAttributes, - CommentAttributesWithoutRefs, } from '../../common/api'; import type { PersistableStateAttachmentTypeRegistry } from '../attachment_framework/persistable_state_registry'; import { @@ -21,11 +22,17 @@ import { extractPersistableStateReferencesFromSO, } from '../attachment_framework/so_references'; import { EXTERNAL_REFERENCE_REF_NAME } from '../common/constants'; -import { isCommentRequestTypeExternalReferenceSO } from '../common/utils'; +import type { + AttachmentPersistedAttributes, + AttachmentRequestAttributes, +} from '../common/types/attachments'; +import { isCommentRequestTypeExternalReferenceSO } from './type_guards'; import type { PartialField } from '../types'; import { SOReferenceExtractor } from './so_reference_extractor'; -export const getAttachmentSOExtractor = (attachment: Partial) => { +export const getAttachmentSOExtractor = ( + attachment: Partial +): SOReferenceExtractor => { const fieldsToExtract = []; if (isCommentRequestTypeExternalReferenceSO(attachment)) { @@ -47,7 +54,7 @@ type OptionalAttributes = PartialField, 'attributes'>; * then the error field will be set and attributes will be undefined. */ export const injectAttachmentAttributesAndHandleErrors = ( - savedObject: OptionalAttributes, + savedObject: OptionalAttributes, persistableStateAttachmentTypeRegistry: PersistableStateAttachmentTypeRegistry ): OptionalAttributes => { if (!hasAttributes(savedObject)) { @@ -64,9 +71,9 @@ const hasAttributes = (savedObject: OptionalAttributes): savedObject is Sa }; export const injectAttachmentSOAttributesFromRefs = ( - savedObject: SavedObject, + savedObject: SavedObject, persistableStateAttachmentTypeRegistry: PersistableStateAttachmentTypeRegistry -) => { +): SavedObject => { const soExtractor = getAttachmentSOExtractor(savedObject.attributes); const so = soExtractor.populateFieldsFromReferences(savedObject); const injectedAttributes = injectPersistableReferencesToSO(so.attributes, so.references, { @@ -78,9 +85,9 @@ export const injectAttachmentSOAttributesFromRefs = ( export const injectAttachmentSOAttributesFromRefsForPatch = ( updatedAttributes: CommentPatchAttributes, - savedObject: SavedObjectsUpdateResponse, + savedObject: SavedObjectsUpdateResponse, persistableStateAttachmentTypeRegistry: PersistableStateAttachmentTypeRegistry -) => { +): SavedObjectsUpdateResponse => { const soExtractor = getAttachmentSOExtractor(savedObject.attributes); const so = soExtractor.populateFieldsFromReferencesForPatch({ dataBeforeRequest: updatedAttributes, @@ -101,11 +108,17 @@ export const injectAttachmentSOAttributesFromRefsForPatch = ( } as SavedObjectsUpdateResponse; }; +interface ExtractionResults { + attributes: AttachmentPersistedAttributes; + references: SavedObjectReference[]; + didDeleteOperation: boolean; +} + export const extractAttachmentSORefsFromAttributes = ( attributes: CommentAttributes | CommentPatchAttributes, references: SavedObjectReference[], persistableStateAttachmentTypeRegistry: PersistableStateAttachmentTypeRegistry -) => { +): ExtractionResults => { const soExtractor = getAttachmentSOExtractor(attributes); const { @@ -129,5 +142,5 @@ export const extractAttachmentSORefsFromAttributes = ( }; }; -export const getUniqueReferences = (references: SavedObjectReference[]) => +export const getUniqueReferences = (references: SavedObjectReference[]): SavedObjectReference[] => uniqWith(references, isEqual); diff --git a/x-pack/plugins/cases/server/services/type_guards.ts b/x-pack/plugins/cases/server/services/type_guards.ts new file mode 100644 index 0000000000000..ec4c100b17585 --- /dev/null +++ b/x-pack/plugins/cases/server/services/type_guards.ts @@ -0,0 +1,22 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { CommentRequestExternalReferenceSOType } from '../../common/api'; +import { CommentType, ExternalReferenceStorageType } from '../../common/api'; +import type { AttachmentRequestAttributes } from '../common/types/attachments'; + +/** + * A type narrowing function for external reference saved object attachments. + */ +export const isCommentRequestTypeExternalReferenceSO = ( + context: Partial +): context is CommentRequestExternalReferenceSOType => { + return ( + context.type === CommentType.externalReference && + context.externalReferenceStorage?.type === ExternalReferenceStorageType.savedObject + ); +}; diff --git a/x-pack/plugins/cases/server/services/user_actions/transform.ts b/x-pack/plugins/cases/server/services/user_actions/transform.ts index 1efc991cc59ac..10a6104e15807 100644 --- a/x-pack/plugins/cases/server/services/user_actions/transform.ts +++ b/x-pack/plugins/cases/server/services/user_actions/transform.ts @@ -29,7 +29,7 @@ import { PUSH_CONNECTOR_ID_REFERENCE_NAME, } from '../../common/constants'; import { findConnectorIdReference } from '../transform'; -import { isCommentRequestTypeExternalReferenceSO } from '../../common/utils'; +import { isCommentRequestTypeExternalReferenceSO } from '../type_guards'; import type { PersistableStateAttachmentTypeRegistry } from '../../attachment_framework/persistable_state_registry'; import { injectPersistableReferencesToSO } from '../../attachment_framework/so_references'; import { findReferenceId } from '../../common/references';