9
9
timeSeriesEntities ,
10
10
updateAttribute ,
11
11
updateAttributeFromLoadedWithRefs ,
12
- validateCreatedBy
12
+ validateCreatedBy ,
13
+ validateMarking
13
14
} from '../database/middleware' ;
14
15
import { listAllToEntitiesThroughRelations , listEntities , listEntitiesThroughRelationsPaginated , storeLoadById } from '../database/middleware-loader' ;
15
16
import { elCount , elFindByIds } from '../database/engine' ;
@@ -25,7 +26,7 @@ import {
25
26
isStixDomainObjectLocation ,
26
27
isStixDomainObjectThreatActor
27
28
} from '../schema/stixDomainObject' ;
28
- import { ABSTRACT_STIX_CYBER_OBSERVABLE , ABSTRACT_STIX_DOMAIN_OBJECT , buildRefRelationKey , INPUT_MARKINGS } from '../schema/general' ;
29
+ import { ABSTRACT_STIX_CYBER_OBSERVABLE , ABSTRACT_STIX_DOMAIN_OBJECT , buildRefRelationKey , INPUT_CREATED_BY , INPUT_MARKINGS } from '../schema/general' ;
29
30
import { RELATION_CREATED_BY , RELATION_OBJECT_ASSIGNEE , } from '../schema/stixRefRelationship' ;
30
31
import { askEntityExport , askListExport , exportTransformFilters } from './stix' ;
31
32
import { RELATION_BASED_ON } from '../schema/stixCoreRelationship' ;
@@ -202,12 +203,19 @@ export const stixDomainObjectEditField = async (context, user, stixObjectId, inp
202
203
if ( ! stixDomainObject ) {
203
204
throw FunctionalError ( 'Cannot edit the field, Stix-Domain-Object cannot be found.' ) ;
204
205
}
205
-
206
- const createdByKey = input . find ( ( inputData ) => inputData . key === 'createdBy' ) ;
206
+ // Validate specific relations, created by and markings
207
+ const markingsInput = input . find ( ( inputData ) => inputData . key === INPUT_MARKINGS ) ;
208
+ if ( markingsInput && markingsInput . value ?. length > 0 ) {
209
+ for ( let index = 0 ; index < markingsInput . value . length ; index += 1 ) {
210
+ const markingId = markingsInput . value [ index ] ;
211
+ await validateMarking ( context , user , markingId ) ;
212
+ }
213
+ }
214
+ const createdByKey = input . find ( ( inputData ) => inputData . key === INPUT_CREATED_BY ) ;
207
215
if ( createdByKey && createdByKey . value ?. length > 0 ) {
208
216
await validateCreatedBy ( context , user , createdByKey . value [ 0 ] ) ;
209
217
}
210
-
218
+ // Start the element edition
211
219
const { element : updatedElem } = await updateAttribute ( context , user , stixObjectId , ABSTRACT_STIX_DOMAIN_OBJECT , input , opts ) ;
212
220
// If indicator is score patched, we also patch the score of all observables attached to the indicator
213
221
if ( stixDomainObject . entity_type === ENTITY_TYPE_INDICATOR && input . key === 'x_opencti_score' ) {
@@ -245,7 +253,6 @@ export const stixDomainObjectFileEdit = async (context, user, sdoId, { id, order
245
253
const { [ INPUT_MARKINGS ] : markingInput , ...nonResolvedFile } = f ;
246
254
return nonResolvedFile ;
247
255
} ) ;
248
-
249
256
const { element : updatedElement } = await updateAttributeFromLoadedWithRefs ( context , user , stixDomainObject , { key : 'x_opencti_files' , value : nonResolvedFiles } ) ;
250
257
return notify ( BUS_TOPICS [ ABSTRACT_STIX_DOMAIN_OBJECT ] . EDIT_TOPIC , updatedElement , user ) ;
251
258
} ;
0 commit comments