From f8510dfc4f0de677d015cab453b2137636312fcf Mon Sep 17 00:00:00 2001 From: Samuel Hassine Date: Wed, 21 Sep 2022 16:54:55 +0200 Subject: [PATCH] [api/frontend] Avoid automatic enrichment of files in the content section (#2377) --- opencti-platform/opencti-front/relay.schema.graphql | 8 ++++---- .../common/stix_domain_objects/StixDomainObjectContent.js | 2 +- .../stix_domain_objects/StixDomainObjectContentFiles.js | 2 +- .../opencti-graphql/config/schema/opencti.graphql | 8 ++++---- .../opencti-graphql/src/database/file-storage.js | 4 ++-- .../opencti-graphql/src/domain/stixCoreObject.js | 4 ++-- .../opencti-graphql/src/resolvers/stixCoreObject.js | 2 +- .../opencti-graphql/src/resolvers/stixDomainObject.js | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/opencti-platform/opencti-front/relay.schema.graphql b/opencti-platform/opencti-front/relay.schema.graphql index 43d78f308085..0ee09cf25779 100644 --- a/opencti-platform/opencti-front/relay.schema.graphql +++ b/opencti-platform/opencti-front/relay.schema.graphql @@ -7000,7 +7000,7 @@ type ExternalReferenceEditMutations { relationAdd(input: StixMetaRelationshipAddInput): StixMetaRelationship relationDelete(fromId: StixRef!, relationship_type: String!): ExternalReference askEnrichment(connectorId: ID!): Work - importPush(file: Upload!): File + importPush(file: Upload!, noTriggerImport: Boolean): File } type KillChainPhaseEditMutations { @@ -7019,7 +7019,7 @@ type StixCoreObjectEditMutations { relationDelete(toId: StixRef!, relationship_type: String!): StixCoreObject merge(stixCoreObjectsIds: [String]!): StixCoreObject askEnrichment(connectorId: ID!): Work - importPush(file: Upload!): File + importPush(file: Upload!, noTriggerImport: Boolean): File exportAsk(format: String!, exportType: String!, maxMarkingDefinition: String): [File] exportPush(file: Upload!): Boolean } @@ -7033,7 +7033,7 @@ type StixDomainObjectEditMutations { relationAdd(input: StixMetaRelationshipAddInput): StixMetaRelationship relationsAdd(input: StixMetaRelationshipsAddInput): StixDomainObject relationDelete(toId: StixRef!, relationship_type: String): StixDomainObject - importPush(file: Upload!): File + importPush(file: Upload!, noTriggerImport: Boolean): File exportAsk(format: String!, exportType: String!, maxMarkingDefinition: String): [File] exportPush(file: Upload!): Boolean } @@ -7281,7 +7281,7 @@ type StixCyberObservableEditMutations { relationsAdd(input: StixMetaRelationshipsAddInput): StixCyberObservable relationDelete(toId: StixRef!, relationship_type: String!): StixCyberObservable promote: StixCyberObservable - importPush(file: Upload!): File + importPush(file: Upload!, noTriggerImport: Boolean): File exportAsk(format: String!, exportType: String!, maxMarkingDefinition: String): [File] exportPush(file: Upload!): Boolean } diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectContent.js b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectContent.js index 014ff0c9f8f5..febb1dd90d5a 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectContent.js +++ b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectContent.js @@ -90,7 +90,7 @@ const stixDomainObjectContentUploadExternalReferenceMutation = graphql` $file: Upload! ) { stixDomainObjectEdit(id: $id) { - importPush(file: $file) { + importPush(file: $file, noTriggerImport: true) { id name uploadStatus diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectContentFiles.js b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectContentFiles.js index 9586f4b92df3..95c42d4835ec 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectContentFiles.js +++ b/opencti-platform/opencti-front/src/private/components/common/stix_domain_objects/StixDomainObjectContentFiles.js @@ -66,7 +66,7 @@ export const stixDomainObjectContentFilesUploadStixDomainObjectMutation = graphq $file: Upload! ) { stixDomainObjectEdit(id: $id) { - importPush(file: $file) { + importPush(file: $file, noTriggerImport: true) { id name uploadStatus diff --git a/opencti-platform/opencti-graphql/config/schema/opencti.graphql b/opencti-platform/opencti-graphql/config/schema/opencti.graphql index 900600222994..d08933acb2b1 100644 --- a/opencti-platform/opencti-graphql/config/schema/opencti.graphql +++ b/opencti-platform/opencti-graphql/config/schema/opencti.graphql @@ -10031,7 +10031,7 @@ type ExternalReferenceEditMutations { relationAdd(input: StixMetaRelationshipAddInput): StixMetaRelationship @auth(for: [KNOWLEDGE_KNUPDATE]) relationDelete(fromId: StixRef!, relationship_type: String!): ExternalReference @auth(for: [KNOWLEDGE_KNUPDATE]) askEnrichment(connectorId: ID!): Work @auth(for: [KNOWLEDGE_KNENRICHMENT]) - importPush(file: Upload!): File @auth(for: [KNOWLEDGE_KNUPLOAD]) + importPush(file: Upload!, noTriggerImport: Boolean): File @auth(for: [KNOWLEDGE_KNUPLOAD]) } type KillChainPhaseEditMutations { delete: ID @@ -10051,7 +10051,7 @@ type StixCoreObjectEditMutations { relationDelete(toId: StixRef!, relationship_type: String!): StixCoreObject merge(stixCoreObjectsIds: [String]!): StixCoreObject askEnrichment(connectorId: ID!): Work @auth(for: [KNOWLEDGE_KNENRICHMENT]) - importPush(file: Upload!): File @auth(for: [KNOWLEDGE_KNUPLOAD]) + importPush(file: Upload!, noTriggerImport: Boolean): File @auth(for: [KNOWLEDGE_KNUPLOAD]) exportAsk(format: String!, exportType: String!, maxMarkingDefinition: String): [File] @auth(for: [KNOWLEDGE_KNGETEXPORT_KNASKEXPORT]) exportPush(file: Upload!): Boolean @auth(for: [CONNECTORAPI]) @@ -10069,7 +10069,7 @@ type StixDomainObjectEditMutations { relationAdd(input: StixMetaRelationshipAddInput): StixMetaRelationship @auth(for: [KNOWLEDGE_KNUPDATE]) relationsAdd(input: StixMetaRelationshipsAddInput): StixDomainObject @auth(for: [KNOWLEDGE_KNUPDATE]) relationDelete(toId: StixRef!, relationship_type: String): StixDomainObject @auth(for: [KNOWLEDGE_KNUPDATE]) - importPush(file: Upload!): File @auth(for: [KNOWLEDGE_KNUPLOAD]) + importPush(file: Upload!, noTriggerImport: Boolean): File @auth(for: [KNOWLEDGE_KNUPLOAD]) exportAsk(format: String!, exportType: String!, maxMarkingDefinition: String): [File] @auth(for: [KNOWLEDGE_KNGETEXPORT_KNASKEXPORT]) exportPush(file: Upload!): Boolean @auth(for: [CONNECTORAPI]) @@ -10313,7 +10313,7 @@ type StixCyberObservableEditMutations { relationsAdd(input: StixMetaRelationshipsAddInput): StixCyberObservable @auth(for: [KNOWLEDGE_KNUPDATE]) relationDelete(toId: StixRef!, relationship_type: String!): StixCyberObservable @auth(for: [KNOWLEDGE_KNUPDATE]) promote: StixCyberObservable @auth(for: [KNOWLEDGE_KNUPDATE]) - importPush(file: Upload!): File @auth(for: [KNOWLEDGE_KNUPLOAD]) + importPush(file: Upload!, noTriggerImport: Boolean): File @auth(for: [KNOWLEDGE_KNUPLOAD]) exportAsk(format: String!, exportType: String!, maxMarkingDefinition: String): [File] @auth(for: [KNOWLEDGE_KNGETEXPORT_KNASKEXPORT]) exportPush(file: Upload!): Boolean @auth(for: [CONNECTORAPI]) diff --git a/opencti-platform/opencti-graphql/src/database/file-storage.js b/opencti-platform/opencti-graphql/src/database/file-storage.js index e8993fee7b97..624ae9893b26 100644 --- a/opencti-platform/opencti-graphql/src/database/file-storage.js +++ b/opencti-platform/opencti-graphql/src/database/file-storage.js @@ -233,7 +233,7 @@ export const uploadJobImport = async (user, fileId, fileMime, entityId, opts = { } }; -export const upload = async (user, path, fileUpload, meta = {}) => { +export const upload = async (user, path, fileUpload, meta = {}, noTriggerImport = false) => { const { createReadStream, filename, mimetype, encoding = '' } = await fileUpload; // Upload the data const readStream = createReadStream(); @@ -271,7 +271,7 @@ export const upload = async (user, path, fileUpload, meta = {}) => { uploadStatus: 'complete' }; // Trigger a enrich job for import file if needed - if (path.startsWith('import/') && !path.startsWith('import/pending') && !path.startsWith('import/External-Reference')) { + if (!noTriggerImport && path.startsWith('import/') && !path.startsWith('import/pending') && !path.startsWith('import/External-Reference')) { await uploadJobImport(user, file.id, file.metaData.mimetype, file.metaData.entity_id); } return file; diff --git a/opencti-platform/opencti-graphql/src/domain/stixCoreObject.js b/opencti-platform/opencti-graphql/src/domain/stixCoreObject.js index 18238bc80a73..1f6bcbe8add5 100644 --- a/opencti-platform/opencti-graphql/src/domain/stixCoreObject.js +++ b/opencti-platform/opencti-graphql/src/domain/stixCoreObject.js @@ -186,7 +186,7 @@ export const stixCoreObjectExportPush = async (user, entityId, file) => { }; // endregion -export const stixCoreObjectImportPush = async (user, id, file) => { +export const stixCoreObjectImportPush = async (user, id, file, noTriggerImport = false) => { let lock; const previous = await storeLoadByIdWithRefs(user, id); if (!previous) { @@ -197,7 +197,7 @@ export const stixCoreObjectImportPush = async (user, id, file) => { // Lock the participants that will be merged lock = await lockResource(participantIds); const { internal_id: internalId } = previous; - const up = await upload(user, `import/${previous.entity_type}/${internalId}`, file, { entity_id: internalId }); + const up = await upload(user, `import/${previous.entity_type}/${internalId}`, file, { entity_id: internalId }, noTriggerImport); // Patch the updated_at to force live stream evolution const eventFile = storeFileConverter(user, up); const files = [...(previous.x_opencti_files ?? []).filter((f) => f.id !== up.id), eventFile]; diff --git a/opencti-platform/opencti-graphql/src/resolvers/stixCoreObject.js b/opencti-platform/opencti-graphql/src/resolvers/stixCoreObject.js index f1bc79d1d886..51166724010e 100644 --- a/opencti-platform/opencti-graphql/src/resolvers/stixCoreObject.js +++ b/opencti-platform/opencti-graphql/src/resolvers/stixCoreObject.js @@ -83,7 +83,7 @@ const stixCoreObjectResolvers = { relationDelete: ({ toId, relationship_type: relationshipType }) => stixCoreObjectDeleteRelation(user, id, toId, relationshipType), merge: ({ stixCoreObjectsIds }) => stixCoreObjectMerge(user, id, stixCoreObjectsIds), askEnrichment: ({ connectorId }) => askElementEnrichmentForConnector(user, id, connectorId), - importPush: ({ file }) => stixCoreObjectImportPush(user, id, file), + importPush: ({ file, noTriggerImport = false }) => stixCoreObjectImportPush(user, id, file, noTriggerImport), exportAsk: (args) => stixCoreObjectExportAsk(user, R.assoc('stixCoreObjectId', id, args)), exportPush: ({ file }) => stixCoreObjectExportPush(user, id, file), }), diff --git a/opencti-platform/opencti-graphql/src/resolvers/stixDomainObject.js b/opencti-platform/opencti-graphql/src/resolvers/stixDomainObject.js index 4c4edbb6127c..d33bf1dc0ecd 100644 --- a/opencti-platform/opencti-graphql/src/resolvers/stixDomainObject.js +++ b/opencti-platform/opencti-graphql/src/resolvers/stixDomainObject.js @@ -74,7 +74,7 @@ const stixDomainObjectResolvers = { relationAdd: ({ input }) => stixDomainObjectAddRelation(user, id, input), relationsAdd: ({ input }) => stixDomainObjectAddRelations(user, id, input), relationDelete: ({ toId, relationship_type: relationshipType }) => stixDomainObjectDeleteRelation(user, id, toId, relationshipType), - importPush: ({ file }) => stixCoreObjectImportPush(user, id, file), + importPush: ({ file, noTriggerImport = false }) => stixCoreObjectImportPush(user, id, file, noTriggerImport), exportAsk: (args) => stixDomainObjectExportAsk(user, R.assoc('stixDomainObjectId', id, args)), exportPush: ({ file }) => stixDomainObjectExportPush(user, id, file), }),