Skip to content

Commit

Permalink
[backend] Fix STIX relationship filters
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine committed Sep 21, 2023
1 parent 6f64743 commit 114fc9b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ const StixRelationshipsHorizontalBars = ({
? n.entity.entity_type
: n.label,
),
}));²
}));
const chartData = [{ name: t('Number of relationships'), data }];
const redirectionUtils = finalField.endsWith('_id')
? props.stixRelationshipsDistribution.map((n) => ({
Expand Down
20 changes: 18 additions & 2 deletions opencti-platform/opencti-graphql/src/domain/stixRelationship.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../database/middleware';
import {
ABSTRACT_STIX_CORE_OBJECT,
ABSTRACT_STIX_RELATIONSHIP,
ABSTRACT_STIX_RELATIONSHIP, buildRefRelationKey,
ENTITY_TYPE_IDENTITY
} from '../schema/general';
import { buildEntityFilters, listEntities, listRelations, storeLoadById } from '../database/middleware-loader';
Expand All @@ -18,7 +18,12 @@ import {
READ_INDEX_STIX_CORE_RELATIONSHIPS, READ_INDEX_STIX_SIGHTING_RELATIONSHIPS
} from '../database/utils';
import { elCount } from '../database/engine';
import { RELATION_CREATED_BY, RELATION_OBJECT_MARKING } from '../schema/stixRefRelationship';
import {
RELATION_CREATED_BY,
RELATION_KILL_CHAIN_PHASE,
RELATION_OBJECT_LABEL,
RELATION_OBJECT_MARKING
} from '../schema/stixRefRelationship';
import { ENTITY_TYPE_MARKING_DEFINITION } from '../schema/stixMetaObject';
import { STIX_SPEC_VERSION, stixCoreRelationshipsMapping } from '../database/stix';
import { UnsupportedError } from '../config/errors';
Expand Down Expand Up @@ -218,3 +223,14 @@ const mergeEntries = (entries) => entries.reduce((result, currentItem) => {
}
return result;
}, []);

export const stixRelationshipOptions = {
StixRelationshipsFilter: {
creator: 'creator_id',
createdBy: buildRefRelationKey(RELATION_CREATED_BY),
markedBy: buildRefRelationKey(RELATION_OBJECT_MARKING),
labelledBy: buildRefRelationKey(RELATION_OBJECT_LABEL),
killChainPhase: buildRefRelationKey(RELATION_KILL_CHAIN_PHASE),
},
StixRelationshipsOrdering: {}
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
stixRelationshipsDistribution,
stixRelationshipsMultiTimeSeries,
stixRelationshipsNumber,
schemaRelationsTypesMapping
schemaRelationsTypesMapping,
stixRelationshipOptions,
} from '../domain/stixRelationship';
import { ABSTRACT_STIX_CORE_RELATIONSHIP, } from '../schema/general';
import { STIX_SIGHTING_RELATIONSHIP } from '../schema/stixSightingRelationship';
Expand All @@ -33,6 +34,8 @@ const stixRelationshipResolvers = {
stixRelationshipsNumber: (_, args, context) => stixRelationshipsNumber(context, context.user, args),
schemaRelationsTypesMapping: () => schemaRelationsTypesMapping(),
},
StixRelationshipsFilter: stixRelationshipOptions.StixRelationshipsFilter,
StixRelationshipsOrdering: stixRelationshipOptions.StixRelationshipsOrdering,
StixRelationship: {
from: (rel, _, context) => loadByIdLoader.load(rel.fromId, context, context.user),
to: (rel, _, context) => loadByIdLoader.load(rel.toId, context, context.user),
Expand Down

0 comments on commit 114fc9b

Please sign in to comment.