Skip to content

Commit

Permalink
[backend] Update x_opencti_files definition to update carousel and ot…
Browse files Browse the repository at this point in the history
…her attributes

Co-authored-by: Julien Richard <[email protected]>
  • Loading branch information
Kedae and richard-julien committed Feb 28, 2024
1 parent 9151d48 commit d9ecbdc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
15 changes: 12 additions & 3 deletions opencti-platform/opencti-graphql/src/domain/stixDomainObject.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import * as R from 'ramda';
import { BUS_TOPICS } from '../config/conf';
import { delEditContext, notify, setEditContext } from '../database/redis';
import { createEntity, deleteElementById, distributionEntities, timeSeriesEntities, updateAttribute } from '../database/middleware';
import {
createEntity,
deleteElementById,
distributionEntities,
storeLoadByIdWithRefs,
timeSeriesEntities,
updateAttribute,
updateAttributeFromLoadedWithRefs
} from '../database/middleware';
import { listAllToEntitiesThroughRelations, listEntities, listEntitiesThroughRelationsPaginated, storeLoadById } from '../database/middleware-loader';
import { elCount, elFindByIds } from '../database/engine';
import { workToExportFile } from './work';
Expand Down Expand Up @@ -217,14 +225,15 @@ export const stixDomainObjectEditField = async (context, user, stixObjectId, inp
};

export const stixDomainObjectFileEdit = async (context, user, sdoId, { id, order, description, inCarousel }) => {
const stixDomainObject = await findById(context, user, sdoId);
const stixDomainObject = await storeLoadByIdWithRefs(context, user, sdoId);
const files = stixDomainObject.x_opencti_files.map((file) => {
if (file.id === id) {
return { ...file, order, description, inCarousel };
}
return file;
});
const { element: updatedElement } = await updateAttribute(context, user, sdoId, ABSTRACT_STIX_DOMAIN_OBJECT, [{ key: 'x_opencti_files', value: files }]);

const { element: updatedElement } = await updateAttributeFromLoadedWithRefs(context, user, stixDomainObject, { key: 'x_opencti_files', value: files });
return notify(BUS_TOPICS[ABSTRACT_STIX_DOMAIN_OBJECT].EDIT_TOPIC, updatedElement, user);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ const stixDomainObjectsAttributes: { [k: string]: Array<AttributeDefinition> } =
[ENTITY_TYPE_THREAT_ACTOR_GROUP]: [
iAliasedIds,
aliases,
{ ...files, update: true },
{ name: 'name', label: 'Name', type: 'string', format: 'short', mandatoryType: 'external', editDefault: true, multiple: false, upsert: true, isFilterable: true },
{ name: 'description', label: 'Description', type: 'string', format: 'text', mandatoryType: 'customizable', editDefault: true, multiple: false, upsert: true, isFilterable: true },
{ name: 'threat_actor_types', label: 'Threat actor types', format: 'vocabulary', type: 'string', vocabularyCategory: 'threat_actor_group_type_ov', mandatoryType: 'customizable', editDefault: true, multiple: true, upsert: false, isFilterable: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import { ENTITY_TYPE_EVENT } from '../event/event-types';
import { ENTITY_HASHED_OBSERVABLE_STIX_FILE } from '../../schema/stixCyberObservable';
import { ENTITY_TYPE_LOCATION_ADMINISTRATIVE_AREA } from '../administrativeArea/administrativeArea-types';
import { ENTITY_TYPE_IDENTITY_ORGANIZATION } from '../organization/organization-types';
import { files } from '../../schema/attribute-definition';

interface Measures {
measure: number | null
Expand Down Expand Up @@ -84,7 +83,6 @@ const THREAT_ACTOR_INDIVIDUAL_DEFINITION: ModuleDefinition<StoreEntityThreatActo
},
},
attributes: [
{ ...files, update: true },
{ name: 'name', label: 'Name', type: 'string', format: 'short', mandatoryType: 'external', editDefault: true, multiple: false, upsert: true, isFilterable: true },
{ name: 'description', label: 'Description', type: 'string', format: 'text', mandatoryType: 'customizable', editDefault: true, multiple: false, upsert: true, isFilterable: true },
{ name: 'threat_actor_types', label: 'Threat actor types', type: 'string', format: 'vocabulary', vocabularyCategory: 'threat_actor_individual_type_ov', mandatoryType: 'customizable', editDefault: true, multiple: true, upsert: false, isFilterable: true },
Expand Down

0 comments on commit d9ecbdc

Please sign in to comment.