Skip to content

Commit

Permalink
[api/frontend] Avoid automatic enrichment of files in the content sec…
Browse files Browse the repository at this point in the history
…tion (#2377)
  • Loading branch information
SamuelHassine committed Sep 21, 2022
1 parent 1ae8f50 commit f8510df
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions opencti-platform/opencti-front/relay.schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const stixDomainObjectContentUploadExternalReferenceMutation = graphql`
$file: Upload!
) {
stixDomainObjectEdit(id: $id) {
importPush(file: $file) {
importPush(file: $file, noTriggerImport: true) {
id
name
uploadStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const stixDomainObjectContentFilesUploadStixDomainObjectMutation = graphq
$file: Upload!
) {
stixDomainObjectEdit(id: $id) {
importPush(file: $file) {
importPush(file: $file, noTriggerImport: true) {
id
name
uploadStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand All @@ -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])
Expand Down Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions opencti-platform/opencti-graphql/src/database/file-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions opencti-platform/opencti-graphql/src/domain/stixCoreObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
Expand Down

0 comments on commit f8510df

Please sign in to comment.