From a9c86379a509407db05338d31894cae97379a962 Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Fri, 27 Dec 2024 11:48:05 +0100 Subject: [PATCH 01/15] [frontend] fix stix core object relations counter (refactored in new fragment) & add related entities counter (#8115) --- .../StixCoreObjectKnowledgeBar.jsx | 43 +++++++++++++++++-- .../threats/threat_actors_group/Root.tsx | 7 +-- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx index 03bdd07ce08c..dd0bf35726b0 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx @@ -9,6 +9,7 @@ import MenuItem from '@mui/material/MenuItem'; import ListItemIcon from '@mui/material/ListItemIcon'; import ListItemText from '@mui/material/ListItemText'; import ListSubheader from '@mui/material/ListSubheader'; +import { graphql, useFragment } from 'react-relay'; import { useFormatter } from '../../../../components/i18n'; import useAuth from '../../../../utils/hooks/useAuth'; import { useSettingsMessagesBannerHeight } from '../../settings/settings_messages/SettingsMessagesBanner'; @@ -32,25 +33,59 @@ const useStyles = makeStyles((theme) => ({ toolbar: theme.mixins.toolbar, })); +const stixCoreObjectKnowledgeBarFragment = graphql` + fragment StixCoreObjectKnowledgeBar_stixCoreObject on StixCoreObject { + distributionWithoutRelatedEntities: stixCoreRelationshipsDistribution( + field: "entity_type" + operation: count + relationship_type: [ + "part-of" + "cooperates-with" + "employed-by" + "derived-from" + "attributed-to" + "participates-in" + "uses" + "authored-by" + "targets" + "compromises" + ] + ) { + label + value + } + relatedEntities: stixCoreRelationships(relationship_type: "related-to") { + pageInfo { + globalCount + } + } + } +`; + const StixCoreObjectKnowledgeBar = ({ stixCoreObjectLink, availableSections, - stixCoreObjectsDistribution, - attribution, + queryRef, + attribution = [], }) => { const { t_i18n, n } = useFormatter(); const classes = useStyles(); const location = useLocation(); const { bannerSettings, schema } = useAuth(); const isInAvailableSection = (sections) => R.any((filter) => R.includes(filter, sections), availableSections); + const { distributionWithoutRelatedEntities, relatedEntities } = useFragment( + stixCoreObjectKnowledgeBarFragment, + queryRef, + ); const settingsMessagesBannerHeight = useSettingsMessagesBannerHeight(); - const statistics = stixCoreObjectsDistribution ? R.indexBy(R.prop('label'), stixCoreObjectsDistribution) : {}; + const statistics = distributionWithoutRelatedEntities ? R.indexBy(R.prop('label'), distributionWithoutRelatedEntities) : {}; const statisticsThreats = R.sum(R.values(R.pick(['Threat-Actor-Individual', 'Threat-Actor-Group', 'Intrusion-Set', 'Campaign', 'Incident'], statistics)).map((o) => o.value)); const statisticsThreatActors = R.sum(R.values(R.pick(['Threat-Actor-Individual', 'Threat-Actor-Group'], statistics)).map((o) => o.value)); const statisticsVictims = R.sum(R.values(R.pick(['Sector', 'Organization', 'Individual', 'Region', 'Country', 'City', 'Position', 'Administrative-Area'], statistics)).map((o) => o.value)); const statisticsAttributions = R.sum(R.values(R.pick((attribution ?? []), statistics)).map((o) => o.value)); const statisticsLocations = R.sum(R.values(R.pick(['Region', 'Country', 'City', 'Position', 'Administrative-Area'], statistics)).map((o) => o.value)); const statisticsObservables = R.sum(R.values(R.pick([...schema.scos.map((s) => s.id), 'Ipv4-Addr', 'Ipv6-Addr'], statistics)).map((o) => o.value)); + const statisticsRelatedEntities = relatedEntities ? relatedEntities.pageInfo.globalCount : 0; return ( - + 0 ? ` (${n(statisticsRelatedEntities)}` : ''})`} /> diff --git a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx index d36ba7d8ff33..9174abeb05d5 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx @@ -54,10 +54,7 @@ const ThreatActorGroupQuery = graphql` name aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...ThreatActorGroup_ThreatActorGroup ...ThreatActorGroupKnowledge_ThreatActorGroup ...FileImportViewer_entity @@ -131,7 +128,7 @@ const RootThreatActorGroup = ({ queryRef, threatActorGroupId }: RootThreatActorG 'infrastructures', 'sightings', ]} - stixCoreObjectsDistribution={threatActorGroup.stixCoreObjectsDistribution} + queryRef={threatActorGroup} /> } /> From b740b2d7c27d5152e7782ffae5ad210ae7f01023 Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Fri, 27 Dec 2024 16:34:50 +0100 Subject: [PATCH 02/15] [frontend] fix located-at and typo (#8115) --- .../common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx index dd0bf35726b0..12d65c4eb53d 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx @@ -49,6 +49,7 @@ const stixCoreObjectKnowledgeBarFragment = graphql` "authored-by" "targets" "compromises" + "located-at" ] ) { label @@ -780,7 +781,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelatedEntities)}` : ''})`} /> + 0 ? ` (${n(statisticsRelatedEntities)})` : ''}`} /> @@ -791,6 +792,7 @@ StixCoreObjectKnowledgeBar.propTypes = { id: PropTypes.string, stixCoreObjectLink: PropTypes.string, availableSections: PropTypes.array, + queryRef: PropTypes.object, attribution: PropTypes.arrayOf(PropTypes.string), }; From 89319fee8f7b7280d9c83a794c75b99c6768b018 Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Fri, 27 Dec 2024 16:44:07 +0100 Subject: [PATCH 03/15] [frontend] refactor root query with knowledge bar fragment (#8115) --- .../src/private/components/arsenal/channels/Root.tsx | 7 ++----- .../src/private/components/arsenal/malwares/Root.tsx | 7 ++----- .../src/private/components/arsenal/tools/Root.tsx | 7 ++----- .../private/components/arsenal/vulnerabilities/Root.tsx | 9 +++------ .../src/private/components/entities/events/Root.tsx | 7 ++----- .../src/private/components/entities/individuals/Root.tsx | 7 ++----- .../private/components/entities/organizations/Root.tsx | 7 ++----- .../src/private/components/entities/sectors/Root.tsx | 7 ++----- .../src/private/components/entities/systems/Root.tsx | 7 ++----- .../src/private/components/events/incidents/Root.tsx | 7 ++----- .../components/locations/administrative_areas/Root.tsx | 7 ++----- .../src/private/components/locations/cities/Root.tsx | 7 ++----- .../src/private/components/locations/countries/Root.tsx | 7 ++----- .../src/private/components/locations/positions/Root.tsx | 7 ++----- .../src/private/components/locations/regions/Root.tsx | 7 ++----- .../infrastructures/InfrastructureKnowledge.tsx | 7 ++----- .../components/techniques/attack_patterns/Root.tsx | 7 ++----- .../private/components/techniques/narratives/Root.tsx | 7 ++----- .../src/private/components/threats/campaigns/Root.tsx | 7 ++----- .../private/components/threats/intrusion_sets/Root.tsx | 7 ++----- .../components/threats/threat_actors_individual/Root.tsx | 7 ++----- 21 files changed, 43 insertions(+), 106 deletions(-) diff --git a/opencti-platform/opencti-front/src/private/components/arsenal/channels/Root.tsx b/opencti-platform/opencti-front/src/private/components/arsenal/channels/Root.tsx index 4d6f35f7c8b2..b3368637d99a 100644 --- a/opencti-platform/opencti-front/src/private/components/arsenal/channels/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/arsenal/channels/Root.tsx @@ -52,10 +52,7 @@ const channelQuery = graphql` name aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Channel_channel ...ChannelKnowledge_channel ...FileImportViewer_entity @@ -124,7 +121,7 @@ const RootChannel = ({ queryRef, channelId }: RootChannelProps) => { 'sightings', 'channels', ]} - stixCoreObjectsDistribution={channel.stixCoreObjectsDistribution} + queryRef={channel} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/arsenal/malwares/Root.tsx b/opencti-platform/opencti-front/src/private/components/arsenal/malwares/Root.tsx index 187e0b591540..47c2abb4dd2c 100644 --- a/opencti-platform/opencti-front/src/private/components/arsenal/malwares/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/arsenal/malwares/Root.tsx @@ -55,10 +55,7 @@ const malwareQuery = graphql` name aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Malware_malware ...MalwareKnowledge_malware ...FileImportViewer_entity @@ -131,7 +128,7 @@ const RootMalware = ({ queryRef, malwareId }: RootMalwareProps) => { 'infrastructures', 'sightings', ]} - stixCoreObjectsDistribution={malware.stixCoreObjectsDistribution} + queryRef={malware} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/arsenal/tools/Root.tsx b/opencti-platform/opencti-front/src/private/components/arsenal/tools/Root.tsx index 1f4966941be8..9f1623148590 100644 --- a/opencti-platform/opencti-front/src/private/components/arsenal/tools/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/arsenal/tools/Root.tsx @@ -52,10 +52,7 @@ const toolQuery = graphql` name aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Tool_tool ...ToolKnowledge_tool ...FileImportViewer_entity @@ -124,7 +121,7 @@ const RootTool = ({ queryRef, toolId }: RootToolProps) => { 'observables', 'sightings', ]} - stixCoreObjectsDistribution={tool.stixCoreObjectsDistribution} + queryRef={tool} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/arsenal/vulnerabilities/Root.tsx b/opencti-platform/opencti-front/src/private/components/arsenal/vulnerabilities/Root.tsx index a2bcb8a3b8de..a65c1d72c8be 100644 --- a/opencti-platform/opencti-front/src/private/components/arsenal/vulnerabilities/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/arsenal/vulnerabilities/Root.tsx @@ -52,10 +52,7 @@ const vulnerabilityQuery = graphql` name x_opencti_aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Vulnerability_vulnerability ...VulnerabilityKnowledge_vulnerability ...FileImportViewer_entity @@ -124,9 +121,9 @@ const RootVulnerability = ({ queryRef, vulnerabilityId }: RootVulnerabilityProps 'sightings', 'infrastructures', ]} - stixCoreObjectsDistribution={vulnerability.stixCoreObjectsDistribution} + queryRef={vulnerability} /> - } + } />
diff --git a/opencti-platform/opencti-front/src/private/components/entities/events/Root.tsx b/opencti-platform/opencti-front/src/private/components/entities/events/Root.tsx index fb9c7285e473..c2a9677d3def 100644 --- a/opencti-platform/opencti-front/src/private/components/entities/events/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/entities/events/Root.tsx @@ -51,10 +51,7 @@ const eventQuery = graphql` entity_type name aliases - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Event_event ...EventKnowledge_event ...FileImportViewer_entity @@ -121,7 +118,7 @@ const RootEvent = ({ eventId, queryRef }: RootEventProps) => { 'tools', 'observables', ]} - stixCoreObjectsDistribution={event.stixCoreObjectsDistribution} + queryRef={event} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/entities/individuals/Root.tsx b/opencti-platform/opencti-front/src/private/components/entities/individuals/Root.tsx index debe73c7df08..91d74e769c52 100644 --- a/opencti-platform/opencti-front/src/private/components/entities/individuals/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/entities/individuals/Root.tsx @@ -55,10 +55,7 @@ const individualQuery = graphql` entity_type name x_opencti_aliases - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Individual_individual ...IndividualKnowledge_individual ...FileImportViewer_entity @@ -155,7 +152,7 @@ const RootIndividual = ({ individualId, queryRef }: RootIndividualProps) => { 'tools', 'observables', ]} - stixCoreObjectsDistribution={individual.stixCoreObjectsDistribution} + queryRef={individual} /> )} /> diff --git a/opencti-platform/opencti-front/src/private/components/entities/organizations/Root.tsx b/opencti-platform/opencti-front/src/private/components/entities/organizations/Root.tsx index b2f3930f70df..c180eb381d3f 100644 --- a/opencti-platform/opencti-front/src/private/components/entities/organizations/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/entities/organizations/Root.tsx @@ -54,10 +54,7 @@ const organizationQuery = graphql` entity_type name x_opencti_aliases - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Organization_organization ...OrganizationKnowledge_organization ...FileImportViewer_entity @@ -153,7 +150,7 @@ const RootOrganization = ({ organizationId, queryRef }: RootOrganizationProps) = 'vulnerabilities', 'observables', ]} - stixCoreObjectsDistribution={organization.stixCoreObjectsDistribution} + queryRef={organization} /> )} /> diff --git a/opencti-platform/opencti-front/src/private/components/entities/sectors/Root.tsx b/opencti-platform/opencti-front/src/private/components/entities/sectors/Root.tsx index c6b16fdb561f..76f4b5a39df8 100644 --- a/opencti-platform/opencti-front/src/private/components/entities/sectors/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/entities/sectors/Root.tsx @@ -53,10 +53,7 @@ const sectorQuery = graphql` name x_opencti_aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Sector_sector ...SectorKnowledge_sector ...FileImportViewer_entity @@ -123,7 +120,7 @@ const RootSector = ({ sectorId, queryRef }: RootSectorProps) => { 'tools', 'observables', ]} - stixCoreObjectsDistribution={sector.stixCoreObjectsDistribution} + queryRef={sector} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/entities/systems/Root.tsx b/opencti-platform/opencti-front/src/private/components/entities/systems/Root.tsx index b0d9000aa6f7..bcab11159020 100644 --- a/opencti-platform/opencti-front/src/private/components/entities/systems/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/entities/systems/Root.tsx @@ -53,10 +53,7 @@ const systemQuery = graphql` entity_type name x_opencti_aliases - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...System_system ...SystemKnowledge_system ...FileImportViewer_entity @@ -148,7 +145,7 @@ const RootSystem = ({ systemId, queryRef }: RootSystemProps) => { 'observables', 'vulnerabilities', ]} - stixCoreObjectsDistribution={system.stixCoreObjectsDistribution} + queryRef={system} /> )} /> diff --git a/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx b/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx index 73be4d747626..803eeba29c6c 100644 --- a/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx @@ -56,10 +56,7 @@ const incidentQuery = graphql` name aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Incident_incident ...IncidentKnowledge_incident ...StixCoreObjectContent_stixCoreObject @@ -123,7 +120,7 @@ const RootIncidentComponent = ({ queryRef }) => { 'vulnerabilities', 'observables', ]} - stixCoreObjectsDistribution={incident.stixCoreObjectsDistribution} + queryRef={incident} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/locations/administrative_areas/Root.tsx b/opencti-platform/opencti-front/src/private/components/locations/administrative_areas/Root.tsx index 51bf20ded588..ce5d2b0455a2 100644 --- a/opencti-platform/opencti-front/src/private/components/locations/administrative_areas/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/locations/administrative_areas/Root.tsx @@ -54,10 +54,7 @@ const administrativeAreaQuery = graphql` name x_opencti_aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...AdministrativeArea_administrativeArea ...AdministrativeAreaKnowledge_administrativeArea ...FileImportViewer_entity @@ -120,7 +117,7 @@ const RootAdministrativeAreaComponent = ({ queryRef, administrativeAreaId }) => 'tools', 'observables', ]} - stixCoreObjectsDistribution={administrativeArea.stixCoreObjectsDistribution} + queryRef={administrativeArea} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/locations/cities/Root.tsx b/opencti-platform/opencti-front/src/private/components/locations/cities/Root.tsx index 5e42b25efffc..47d468b82d99 100644 --- a/opencti-platform/opencti-front/src/private/components/locations/cities/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/locations/cities/Root.tsx @@ -54,10 +54,7 @@ const cityQuery = graphql` name x_opencti_aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...City_city ...CityKnowledge_city ...FileImportViewer_entity @@ -118,7 +115,7 @@ const RootCityComponent = ({ queryRef, cityId }) => { 'tools', 'observables', ]} - stixCoreObjectsDistribution={city.stixCoreObjectsDistribution} + queryRef={city} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/locations/countries/Root.tsx b/opencti-platform/opencti-front/src/private/components/locations/countries/Root.tsx index 320cb27979ac..4d84f46fe18c 100644 --- a/opencti-platform/opencti-front/src/private/components/locations/countries/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/locations/countries/Root.tsx @@ -54,10 +54,7 @@ const countryQuery = graphql` name x_opencti_aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Country_country ...CountryKnowledge_country ...FileImportViewer_entity @@ -120,7 +117,7 @@ const RootCountryComponent = ({ queryRef, countryId }) => { 'tools', 'observables', ]} - stixCoreObjectsDistribution={country.stixCoreObjectsDistribution} + queryRef={country} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/locations/positions/Root.tsx b/opencti-platform/opencti-front/src/private/components/locations/positions/Root.tsx index 1813fde0eb13..bfb26a0d6403 100644 --- a/opencti-platform/opencti-front/src/private/components/locations/positions/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/locations/positions/Root.tsx @@ -51,10 +51,7 @@ const positionQuery = graphql` entity_type name x_opencti_aliases - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Position_position ...PositionKnowledge_position ...FileImportViewer_entity @@ -125,7 +122,7 @@ const RootPosition = ({ positionId, queryRef }: RootPositionProps) => { 'tools', 'observables', ]} - stixCoreObjectsDistribution={position.stixCoreObjectsDistribution} + queryRef={position} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/locations/regions/Root.tsx b/opencti-platform/opencti-front/src/private/components/locations/regions/Root.tsx index 7fc4738d2d11..a9c39c5bc723 100644 --- a/opencti-platform/opencti-front/src/private/components/locations/regions/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/locations/regions/Root.tsx @@ -55,10 +55,7 @@ const regionQuery = graphql` name x_opencti_aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Region_region ...RegionKnowledge_region ...FileImportViewer_entity @@ -122,7 +119,7 @@ const RootRegionComponent = ({ queryRef, regionId }) => { 'tools', 'observables', ]} - stixCoreObjectsDistribution={region.stixCoreObjectsDistribution} + queryRef={region} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/observations/infrastructures/InfrastructureKnowledge.tsx b/opencti-platform/opencti-front/src/private/components/observations/infrastructures/InfrastructureKnowledge.tsx index 8794ec36e6e3..d88da3ae837d 100644 --- a/opencti-platform/opencti-front/src/private/components/observations/infrastructures/InfrastructureKnowledge.tsx +++ b/opencti-platform/opencti-front/src/private/components/observations/infrastructures/InfrastructureKnowledge.tsx @@ -22,10 +22,7 @@ const infrastructureKnowledgeFragment = graphql` aliases first_seen last_seen - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject } `; @@ -39,7 +36,7 @@ const InfrastructureKnowledge = ({ infrastructure }: { infrastructure: Infrastru <> } /> diff --git a/opencti-platform/opencti-front/src/private/components/techniques/narratives/Root.tsx b/opencti-platform/opencti-front/src/private/components/techniques/narratives/Root.tsx index fea04a408c2b..6a2ab8206e60 100644 --- a/opencti-platform/opencti-front/src/private/components/techniques/narratives/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/techniques/narratives/Root.tsx @@ -52,10 +52,7 @@ const narrativeQuery = graphql` name aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Narrative_narrative ...NarrativeKnowledge_narrative ...FileImportViewer_entity @@ -118,7 +115,7 @@ const RootNarrative = ({ narrativeId, queryRef }: RootNarrativeProps) => { 'observables', 'sightings', ]} - stixCoreObjectsDistribution={narrative.stixCoreObjectsDistribution} + queryRef={narrative} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/threats/campaigns/Root.tsx b/opencti-platform/opencti-front/src/private/components/threats/campaigns/Root.tsx index de6997f02870..c3be18cd0f08 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/campaigns/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/threats/campaigns/Root.tsx @@ -53,10 +53,7 @@ const campaignQuery = graphql` name aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...Campaign_campaign ...CampaignKnowledge_campaign ...FileImportViewer_entity @@ -127,7 +124,7 @@ const RootCampaign = ({ campaignId, queryRef }: RootCampaignProps) => { 'infrastructures', 'sightings', ]} - stixCoreObjectsDistribution={campaign.stixCoreObjectsDistribution} + queryRef={campaign} attribution={['Intrusion-Set', 'Threat-Actor-Individual', 'Threat-Actor-Group']} /> } diff --git a/opencti-platform/opencti-front/src/private/components/threats/intrusion_sets/Root.tsx b/opencti-platform/opencti-front/src/private/components/threats/intrusion_sets/Root.tsx index f149b9ee75ab..38d7b71e433d 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/intrusion_sets/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/threats/intrusion_sets/Root.tsx @@ -57,10 +57,7 @@ const intrusionSetQuery = graphql` id } x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...IntrusionSet_intrusionSet ...IntrusionSetKnowledge_intrusionSet ...FileImportViewer_entity @@ -133,7 +130,7 @@ const RootIntrusionSet = ({ intrusionSetId, queryRef }: RootIntrusionSetProps) = 'infrastructures', 'sightings', ]} - stixCoreObjectsDistribution={intrusionSet.stixCoreObjectsDistribution} + queryRef={intrusionSet} attribution={['Threat-Actor-Individual', 'Threat-Actor-Group']} /> } diff --git a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx index 3be9eec96fc5..c6a9d0602a0f 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx @@ -54,10 +54,7 @@ const ThreatActorIndividualQuery = graphql` name aliases x_opencti_graph_data - stixCoreObjectsDistribution(field: "entity_type", operation: count) { - label - value - } + ...StixCoreObjectKnowledgeBar_stixCoreObject ...ThreatActorIndividual_ThreatActorIndividual ...ThreatActorIndividualKnowledge_ThreatActorIndividual ...FileImportViewer_entity @@ -144,7 +141,7 @@ const RootThreatActorIndividualComponent = ({ 'sightings', 'countries', ]} - stixCoreObjectsDistribution={threatActorIndividual.stixCoreObjectsDistribution} + queryRef={threatActorIndividual} /> } /> From 616d5b13e3f30777c9337912b1587be10fc429d9 Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Fri, 27 Dec 2024 17:20:30 +0100 Subject: [PATCH 04/15] [frontend] fix tslint (#8115) --- .../common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx index 12d65c4eb53d..4dad8cf85193 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx @@ -67,7 +67,7 @@ const StixCoreObjectKnowledgeBar = ({ stixCoreObjectLink, availableSections, queryRef, - attribution = [], + attribution, }) => { const { t_i18n, n } = useFormatter(); const classes = useStyles(); From c1159c95dd88a741fbfba95fc46d45934be749ee Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Fri, 3 Jan 2025 10:45:45 +0100 Subject: [PATCH 05/15] [frontend] remove ramda includes (#8115) --- .../StixCoreObjectKnowledgeBar.jsx | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx index 4dad8cf85193..1c63e02a5bdc 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx @@ -124,7 +124,7 @@ const StixCoreObjectKnowledgeBar = ({ } > - {R.includes('sectors', availableSections) && ( + {availableSections.includes('sectors') && ( 0 ? ` (${n(statistics.Sector.value)})` : ''}`} /> )} - {R.includes('regions', availableSections) && ( + {availableSections.includes('regions') && ( 0 ? ` (${n(statistics.Region.value)})` : ''}`} /> )} - {R.includes('countries', availableSections) && ( + {availableSections.includes('countries') && ( 0 ? ` (${n(statistics.Country.value)})` : ''}`} /> )} - {R.includes('areas', availableSections) && ( + {availableSections.includes('areas') && ( 0 ? ` (${n(statistics['Administrative-Area'].value)})` : ''}`} /> )} - {R.includes('cities', availableSections) && ( + {availableSections.includes('cities') && ( 0 ? ` (${n(statistics.City.value)})` : ''}`} /> )} - {R.includes('organizations', availableSections) && ( + {availableSections.includes('organizations') && ( 0 ? ` (${n(statistics.Organization.value)})` : ''}`} /> )} - {R.includes('individuals', availableSections) && ( + {availableSections.includes('individuals') && ( 0 ? ` (${n(statistics.Individual.value)})` : ''}`} /> )} - {R.includes('locations', availableSections) && ( + {availableSections.includes('locations') && ( 0 ? ` (${n(statisticsLocations)})` : ''}`} /> )} - {R.includes('used_tools', availableSections) && ( + {availableSections.includes('used_tools') && ( ) : ( <> - {R.includes('sectors', availableSections) && ( + {availableSections.includes('sectors') && ( 0 ? ` (${n(statistics.Sector.value)})` : ''}`} /> )} - {R.includes('regions', availableSections) && ( + {availableSections.includes('regions') && ( 0 ? ` (${n(statistics.Region.value)})` : ''}`} /> )} - {R.includes('countries', availableSections) && ( + {availableSections.includes('countries') && ( 0 ? ` (${n(statistics.Country.value)})` : ''}`} /> )} - {R.includes('areas', availableSections) && ( + {availableSections.includes('areas') && ( 0 ? ` (${n(statistics['Administrative-Area'].value)})` : ''}`} /> )} - {R.includes('cities', availableSections) && ( + {availableSections.includes('cities') && ( 0 ? ` (${n(statistics.City.value)})` : ''}`} /> )} - {R.includes('locations', availableSections) && ( + {availableSections.includes('locations') && ( 0 ? ` (${n(statisticsLocations)})` : ''}`} /> )} - {R.includes('organizations', availableSections) && ( + {availableSections.includes('organizations') && ( 0 ? ` (${n(statistics.Organization.value)})` : ''}`} /> )} - {R.includes('individuals', availableSections) && ( + {availableSections.includes('individuals') && ( 0 ? ` (${n(statistics.Individual.value)})` : ''}`} /> )} - {R.includes('used_tools', availableSections) && ( + {availableSections.includes('used_tools') && ( {t_i18n('Threats')} } > - {R.includes('threats', availableSections) && ( + {availableSections.includes('threats') && ( 0 ? ` (${n(statisticsThreats)})` : ''}`} /> )} - {R.includes('attribution', availableSections) && ( + {availableSections.includes('attribution') && ( 0 ? ` (${n(statisticsAttributions)})` : ''}`} /> )} - {R.includes('victimology', availableSections) && ( + {availableSections.includes('victimology') && ( 0 ? ` (${n(statisticsVictims)})` : ''}`} /> )} - {R.includes('threat_actors', availableSections) && ( + {availableSections.includes('threat_actors') && ( 0 ? ` (${n(statisticsThreatActors)})` : ''}`} /> )} - {R.includes('intrusion_sets', availableSections) && ( + {availableSections.includes('intrusion_sets') && ( 0 ? ` (${n(statistics['Intrusion-Set'].value)})` : ''}`} /> )} - {R.includes('campaigns', availableSections) && ( + {availableSections.includes('campaigns') && ( {t_i18n('Arsenal')} } > - {R.includes('variants', availableSections) && ( + {availableSections.includes('variants') && ( 0 ? ` (${n(statistics.Malware.value)})` : ''}`} /> )} - {R.includes('malwares', availableSections) && ( + {availableSections.includes('malwares') && ( 0 ? ` (${n(statistics.Malware.value)})` : ''}`} /> )} - {R.includes('channels', availableSections) && ( + {availableSections.includes('channels') && ( 0 ? ` (${n(statistics.Channel.value)})` : ''}`} /> )} - {R.includes('tools', availableSections) && ( + {availableSections.includes('tools') && ( 0 ? ` (${n(statistics.Tool.value)})` : ''}`} /> )} - {R.includes('vulnerabilities', availableSections) && ( + {availableSections.includes('vulnerabilities') && ( } > - {R.includes('attack_patterns', availableSections) && ( + {availableSections.includes('attack_patterns') && ( 0 ? ` (${n(statistics['Attack-Pattern'].value)})` : ''}`} /> )} - {R.includes('narratives', availableSections) && ( + {availableSections.includes('narratives') && ( } > - {R.includes('indicators', availableSections) && ( + {availableSections.includes('indicators') && ( 0 ? ` (${n(statistics.Indicator.value)})` : ''}`} /> )} - {R.includes('observables', availableSections) && ( + {availableSections.includes('observables') && ( 0 ? ` (${n(statisticsObservables)})` : ''}`} /> )} - {R.includes('infrastructures', availableSections) && ( + {availableSections.includes('infrastructures') && ( {t_i18n('Events')} } > - {R.includes('incidents', availableSections) && ( + {availableSections.includes('incidents') && ( 0 ? ` (${n(statistics.Incident.value)})` : ''}`} /> )} - {R.includes('observed_data', availableSections) && ( + {availableSections.includes('observed_data') && ( 0 ? ` (${n(statistics['Observed-Data'].value)})` : ''}`} /> )} - {R.includes('sightings', availableSections) && ( + {availableSections.includes('sightings') && ( Date: Fri, 3 Jan 2025 18:17:32 +0100 Subject: [PATCH 06/15] [frontend] refactor objects and relationships without related to distribution (#8115) --- .../StixCoreObjectKnowledgeBar.jsx | 96 +++++++++++-------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx index 1c63e02a5bdc..c534f7dde725 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx @@ -1,6 +1,5 @@ import React from 'react'; import PropTypes from 'prop-types'; -import * as R from 'ramda'; import { Link, useLocation } from 'react-router-dom'; import Drawer from '@mui/material/Drawer'; import makeStyles from '@mui/styles/makeStyles'; @@ -35,7 +34,8 @@ const useStyles = makeStyles((theme) => ({ const stixCoreObjectKnowledgeBarFragment = graphql` fragment StixCoreObjectKnowledgeBar_stixCoreObject on StixCoreObject { - distributionWithoutRelatedEntities: stixCoreRelationshipsDistribution( + # distribution of entities without "related to" relationship + relationshipsWithoutRelatedToDistribution: stixCoreRelationshipsDistribution( field: "entity_type" operation: count relationship_type: [ @@ -55,6 +55,14 @@ const stixCoreObjectKnowledgeBarFragment = graphql` label value } + # distribution for observable and indicator type + stixCoreObjectsDistribution( + field: "entity_type", + operation: count, + ) { + label + value + } relatedEntities: stixCoreRelationships(relationship_type: "related-to") { pageInfo { globalCount @@ -73,20 +81,32 @@ const StixCoreObjectKnowledgeBar = ({ const classes = useStyles(); const location = useLocation(); const { bannerSettings, schema } = useAuth(); - const isInAvailableSection = (sections) => R.any((filter) => R.includes(filter, sections), availableSections); - const { distributionWithoutRelatedEntities, relatedEntities } = useFragment( + const isInAvailableSection = (sections) => availableSections.some((filter) => sections.includes(filter)); + const { relationshipsWithoutRelatedToDistribution, stixCoreObjectsDistribution, relatedEntities } = useFragment( stixCoreObjectKnowledgeBarFragment, queryRef, ); const settingsMessagesBannerHeight = useSettingsMessagesBannerHeight(); - const statistics = distributionWithoutRelatedEntities ? R.indexBy(R.prop('label'), distributionWithoutRelatedEntities) : {}; - const statisticsThreats = R.sum(R.values(R.pick(['Threat-Actor-Individual', 'Threat-Actor-Group', 'Intrusion-Set', 'Campaign', 'Incident'], statistics)).map((o) => o.value)); - const statisticsThreatActors = R.sum(R.values(R.pick(['Threat-Actor-Individual', 'Threat-Actor-Group'], statistics)).map((o) => o.value)); - const statisticsVictims = R.sum(R.values(R.pick(['Sector', 'Organization', 'Individual', 'Region', 'Country', 'City', 'Position', 'Administrative-Area'], statistics)).map((o) => o.value)); - const statisticsAttributions = R.sum(R.values(R.pick((attribution ?? []), statistics)).map((o) => o.value)); - const statisticsLocations = R.sum(R.values(R.pick(['Region', 'Country', 'City', 'Position', 'Administrative-Area'], statistics)).map((o) => o.value)); - const statisticsObservables = R.sum(R.values(R.pick([...schema.scos.map((s) => s.id), 'Ipv4-Addr', 'Ipv6-Addr'], statistics)).map((o) => o.value)); + + const indexEntities = (objectsDistribution) => (objectsDistribution + ? objectsDistribution.reduce((acc, item) => ({ ...acc, [item.label]: item }), {}) + : {}); + + const statisticsRelationship = indexEntities(relationshipsWithoutRelatedToDistribution); + const statisticsCoreObjects = indexEntities(stixCoreObjectsDistribution); + + const sumEntitiesByKeys = (keys, stats) => keys + .map((key) => stats[key]?.value || 0) + .reduce((acc, val) => acc + val, 0); + + const statisticsThreats = sumEntitiesByKeys(['Threat-Actor-Individual', 'Threat-Actor-Group', 'Intrusion-Set', 'Campaign', 'Incident'], statisticsRelationship); + const statisticsThreatActors = sumEntitiesByKeys(['Threat-Actor-Individual', 'Threat-Actor-Group'], statisticsRelationship); + const statisticsVictims = sumEntitiesByKeys(['Sector', 'Organization', 'Individual', 'Region', 'Country', 'City', 'Position', 'Administrative-Area'], statisticsRelationship); + const statisticsAttributions = sumEntitiesByKeys(attribution ?? [], statisticsRelationship); + const statisticsLocations = sumEntitiesByKeys(['Region', 'Country', 'City', 'Position', 'Administrative-Area'], statisticsRelationship); + const statisticsObservables = sumEntitiesByKeys([...schema.scos.map((s) => s.id), 'Stixfile', 'Ipv4-Addr', 'Ipv6-Addr'], statisticsCoreObjects); const statisticsRelatedEntities = relatedEntities ? relatedEntities.pageInfo.globalCount : 0; + return ( - 0 ? ` (${n(statistics.Sector.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Sector.value)})` : ''}`} /> )} {availableSections.includes('regions') && ( @@ -149,7 +169,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Region.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Region.value)})` : ''}`} /> )} {availableSections.includes('countries') && ( @@ -165,7 +185,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Country.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Country.value)})` : ''}`} /> )} {availableSections.includes('areas') && ( @@ -179,7 +199,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics['Administrative-Area'].value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship['Administrative-Area'].value)})` : ''}`} /> )} {availableSections.includes('cities') && ( @@ -193,7 +213,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.City.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.City.value)})` : ''}`} /> )} {availableSections.includes('organizations') && ( @@ -209,7 +229,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Organization.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Organization.value)})` : ''}`} /> )} {availableSections.includes('individuals') && ( @@ -225,7 +245,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Individual.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Individual.value)})` : ''}`} /> )} {availableSections.includes('locations') && ( @@ -274,7 +294,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Sector.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Sector.value)})` : ''}`} /> )} {availableSections.includes('regions') && ( @@ -288,7 +308,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Region.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Region.value)})` : ''}`} /> )} {availableSections.includes('countries') && ( @@ -304,7 +324,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Country.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Country.value)})` : ''}`} /> )} {availableSections.includes('areas') && ( @@ -318,7 +338,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics['Administrative-Area'].value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship['Administrative-Area'].value)})` : ''}`} /> )} {availableSections.includes('cities') && ( @@ -332,7 +352,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.City.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.City.value)})` : ''}`} /> )} {availableSections.includes('locations') && ( @@ -364,7 +384,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Organization.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Organization.value)})` : ''}`} /> )} {availableSections.includes('individuals') && ( @@ -380,7 +400,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Individual.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Individual.value)})` : ''}`} /> )} {availableSections.includes('used_tools') && ( @@ -491,7 +511,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics['Intrusion-Set'].value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship['Intrusion-Set'].value)})` : ''}`} /> )} {availableSections.includes('campaigns') && ( @@ -505,7 +525,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Campaign.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Campaign.value)})` : ''}`} /> )} @@ -537,7 +557,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Malware.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Malware.value)})` : ''}`} /> )} {availableSections.includes('malwares') && ( @@ -551,7 +571,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Malware.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Malware.value)})` : ''}`} /> )} {availableSections.includes('channels') && ( @@ -565,7 +585,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Channel.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Channel.value)})` : ''}`} /> )} {availableSections.includes('tools') && ( @@ -579,7 +599,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Tool.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Tool.value)})` : ''}`} /> )} {availableSections.includes('vulnerabilities') && ( @@ -595,7 +615,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Vulnerability.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Vulnerability.value)})` : ''}`} /> )} @@ -623,7 +643,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics['Attack-Pattern'].value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship['Attack-Pattern'].value)})` : ''}`} /> )} {availableSections.includes('narratives') && ( @@ -639,7 +659,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Narrative.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Narrative.value)})` : ''}`} /> )} @@ -672,7 +692,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Indicator.value)})` : ''}`} /> + 0 ? ` (${n(statisticsCoreObjects.Indicator.value)})` : ''}`} /> )} {availableSections.includes('observables') && ( @@ -704,7 +724,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Infrastructure.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Infrastructure.value)})` : ''}`} /> )} @@ -728,7 +748,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics.Incident.value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship.Incident.value)})` : ''}`} /> )} {availableSections.includes('observed_data') && ( @@ -744,7 +764,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statistics['Observed-Data'].value)})` : ''}`} /> + 0 ? ` (${n(statisticsRelationship['Observed-Data'].value)})` : ''}`} /> )} {availableSections.includes('sightings') && ( From 8ed79d0ce9ee5ed6b5db968df9f172694f57780f Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Mon, 6 Jan 2025 10:44:38 +0100 Subject: [PATCH 07/15] [frontend] rename `queryRef` to `data` (#8115) --- .../src/private/components/arsenal/channels/Root.tsx | 2 +- .../src/private/components/arsenal/malwares/Root.tsx | 2 +- .../src/private/components/arsenal/tools/Root.tsx | 2 +- .../src/private/components/arsenal/vulnerabilities/Root.tsx | 2 +- .../common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx | 6 +++--- .../src/private/components/entities/events/Root.tsx | 2 +- .../src/private/components/entities/individuals/Root.tsx | 2 +- .../src/private/components/entities/organizations/Root.tsx | 2 +- .../src/private/components/entities/sectors/Root.tsx | 2 +- .../src/private/components/entities/systems/Root.tsx | 2 +- .../src/private/components/events/incidents/Root.tsx | 2 +- .../components/locations/administrative_areas/Root.tsx | 2 +- .../src/private/components/locations/cities/Root.tsx | 2 +- .../src/private/components/locations/countries/Root.tsx | 2 +- .../src/private/components/locations/positions/Root.tsx | 2 +- .../src/private/components/locations/regions/Root.tsx | 2 +- .../infrastructures/InfrastructureKnowledge.tsx | 2 +- .../private/components/techniques/attack_patterns/Root.tsx | 2 +- .../src/private/components/techniques/narratives/Root.tsx | 2 +- .../src/private/components/threats/campaigns/Root.tsx | 2 +- .../src/private/components/threats/intrusion_sets/Root.tsx | 2 +- .../private/components/threats/threat_actors_group/Root.tsx | 2 +- .../components/threats/threat_actors_individual/Root.tsx | 2 +- 23 files changed, 25 insertions(+), 25 deletions(-) diff --git a/opencti-platform/opencti-front/src/private/components/arsenal/channels/Root.tsx b/opencti-platform/opencti-front/src/private/components/arsenal/channels/Root.tsx index b3368637d99a..0948e46de922 100644 --- a/opencti-platform/opencti-front/src/private/components/arsenal/channels/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/arsenal/channels/Root.tsx @@ -121,7 +121,7 @@ const RootChannel = ({ queryRef, channelId }: RootChannelProps) => { 'sightings', 'channels', ]} - queryRef={channel} + data={channel} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/arsenal/malwares/Root.tsx b/opencti-platform/opencti-front/src/private/components/arsenal/malwares/Root.tsx index 47c2abb4dd2c..9bf559e874d4 100644 --- a/opencti-platform/opencti-front/src/private/components/arsenal/malwares/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/arsenal/malwares/Root.tsx @@ -128,7 +128,7 @@ const RootMalware = ({ queryRef, malwareId }: RootMalwareProps) => { 'infrastructures', 'sightings', ]} - queryRef={malware} + data={malware} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/arsenal/tools/Root.tsx b/opencti-platform/opencti-front/src/private/components/arsenal/tools/Root.tsx index 9f1623148590..2812ed432ac8 100644 --- a/opencti-platform/opencti-front/src/private/components/arsenal/tools/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/arsenal/tools/Root.tsx @@ -121,7 +121,7 @@ const RootTool = ({ queryRef, toolId }: RootToolProps) => { 'observables', 'sightings', ]} - queryRef={tool} + data={tool} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/arsenal/vulnerabilities/Root.tsx b/opencti-platform/opencti-front/src/private/components/arsenal/vulnerabilities/Root.tsx index a65c1d72c8be..17c68d110b28 100644 --- a/opencti-platform/opencti-front/src/private/components/arsenal/vulnerabilities/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/arsenal/vulnerabilities/Root.tsx @@ -121,7 +121,7 @@ const RootVulnerability = ({ queryRef, vulnerabilityId }: RootVulnerabilityProps 'sightings', 'infrastructures', ]} - queryRef={vulnerability} + data={vulnerability} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx index c534f7dde725..63f33bfe3125 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx @@ -74,7 +74,7 @@ const stixCoreObjectKnowledgeBarFragment = graphql` const StixCoreObjectKnowledgeBar = ({ stixCoreObjectLink, availableSections, - queryRef, + data, attribution, }) => { const { t_i18n, n } = useFormatter(); @@ -84,7 +84,7 @@ const StixCoreObjectKnowledgeBar = ({ const isInAvailableSection = (sections) => availableSections.some((filter) => sections.includes(filter)); const { relationshipsWithoutRelatedToDistribution, stixCoreObjectsDistribution, relatedEntities } = useFragment( stixCoreObjectKnowledgeBarFragment, - queryRef, + data, ); const settingsMessagesBannerHeight = useSettingsMessagesBannerHeight(); @@ -812,7 +812,7 @@ StixCoreObjectKnowledgeBar.propTypes = { id: PropTypes.string, stixCoreObjectLink: PropTypes.string, availableSections: PropTypes.array, - queryRef: PropTypes.object, + data: PropTypes.object, attribution: PropTypes.arrayOf(PropTypes.string), }; diff --git a/opencti-platform/opencti-front/src/private/components/entities/events/Root.tsx b/opencti-platform/opencti-front/src/private/components/entities/events/Root.tsx index c2a9677d3def..d23a75393ea2 100644 --- a/opencti-platform/opencti-front/src/private/components/entities/events/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/entities/events/Root.tsx @@ -118,7 +118,7 @@ const RootEvent = ({ eventId, queryRef }: RootEventProps) => { 'tools', 'observables', ]} - queryRef={event} + data={event} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/entities/individuals/Root.tsx b/opencti-platform/opencti-front/src/private/components/entities/individuals/Root.tsx index 91d74e769c52..6c3b237703cb 100644 --- a/opencti-platform/opencti-front/src/private/components/entities/individuals/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/entities/individuals/Root.tsx @@ -152,7 +152,7 @@ const RootIndividual = ({ individualId, queryRef }: RootIndividualProps) => { 'tools', 'observables', ]} - queryRef={individual} + data={individual} /> )} /> diff --git a/opencti-platform/opencti-front/src/private/components/entities/organizations/Root.tsx b/opencti-platform/opencti-front/src/private/components/entities/organizations/Root.tsx index c180eb381d3f..067a78d8b528 100644 --- a/opencti-platform/opencti-front/src/private/components/entities/organizations/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/entities/organizations/Root.tsx @@ -150,7 +150,7 @@ const RootOrganization = ({ organizationId, queryRef }: RootOrganizationProps) = 'vulnerabilities', 'observables', ]} - queryRef={organization} + data={organization} /> )} /> diff --git a/opencti-platform/opencti-front/src/private/components/entities/sectors/Root.tsx b/opencti-platform/opencti-front/src/private/components/entities/sectors/Root.tsx index 76f4b5a39df8..63dfe5bb03fa 100644 --- a/opencti-platform/opencti-front/src/private/components/entities/sectors/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/entities/sectors/Root.tsx @@ -120,7 +120,7 @@ const RootSector = ({ sectorId, queryRef }: RootSectorProps) => { 'tools', 'observables', ]} - queryRef={sector} + data={sector} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/entities/systems/Root.tsx b/opencti-platform/opencti-front/src/private/components/entities/systems/Root.tsx index bcab11159020..3b4c190330e4 100644 --- a/opencti-platform/opencti-front/src/private/components/entities/systems/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/entities/systems/Root.tsx @@ -145,7 +145,7 @@ const RootSystem = ({ systemId, queryRef }: RootSystemProps) => { 'observables', 'vulnerabilities', ]} - queryRef={system} + data={system} /> )} /> diff --git a/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx b/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx index 803eeba29c6c..c2475b54d50b 100644 --- a/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx @@ -120,7 +120,7 @@ const RootIncidentComponent = ({ queryRef }) => { 'vulnerabilities', 'observables', ]} - queryRef={incident} + data={incident} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/locations/administrative_areas/Root.tsx b/opencti-platform/opencti-front/src/private/components/locations/administrative_areas/Root.tsx index ce5d2b0455a2..584e0e2f2d6e 100644 --- a/opencti-platform/opencti-front/src/private/components/locations/administrative_areas/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/locations/administrative_areas/Root.tsx @@ -117,7 +117,7 @@ const RootAdministrativeAreaComponent = ({ queryRef, administrativeAreaId }) => 'tools', 'observables', ]} - queryRef={administrativeArea} + data={administrativeArea} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/locations/cities/Root.tsx b/opencti-platform/opencti-front/src/private/components/locations/cities/Root.tsx index 47d468b82d99..b7805e37e973 100644 --- a/opencti-platform/opencti-front/src/private/components/locations/cities/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/locations/cities/Root.tsx @@ -115,7 +115,7 @@ const RootCityComponent = ({ queryRef, cityId }) => { 'tools', 'observables', ]} - queryRef={city} + data={city} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/locations/countries/Root.tsx b/opencti-platform/opencti-front/src/private/components/locations/countries/Root.tsx index 4d84f46fe18c..a9900e068956 100644 --- a/opencti-platform/opencti-front/src/private/components/locations/countries/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/locations/countries/Root.tsx @@ -117,7 +117,7 @@ const RootCountryComponent = ({ queryRef, countryId }) => { 'tools', 'observables', ]} - queryRef={country} + data={country} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/locations/positions/Root.tsx b/opencti-platform/opencti-front/src/private/components/locations/positions/Root.tsx index bfb26a0d6403..8adc9a4aedde 100644 --- a/opencti-platform/opencti-front/src/private/components/locations/positions/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/locations/positions/Root.tsx @@ -122,7 +122,7 @@ const RootPosition = ({ positionId, queryRef }: RootPositionProps) => { 'tools', 'observables', ]} - queryRef={position} + data={position} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/locations/regions/Root.tsx b/opencti-platform/opencti-front/src/private/components/locations/regions/Root.tsx index a9c39c5bc723..3b118cb157cf 100644 --- a/opencti-platform/opencti-front/src/private/components/locations/regions/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/locations/regions/Root.tsx @@ -119,7 +119,7 @@ const RootRegionComponent = ({ queryRef, regionId }) => { 'tools', 'observables', ]} - queryRef={region} + data={region} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/observations/infrastructures/InfrastructureKnowledge.tsx b/opencti-platform/opencti-front/src/private/components/observations/infrastructures/InfrastructureKnowledge.tsx index d88da3ae837d..fb64fa9e89b9 100644 --- a/opencti-platform/opencti-front/src/private/components/observations/infrastructures/InfrastructureKnowledge.tsx +++ b/opencti-platform/opencti-front/src/private/components/observations/infrastructures/InfrastructureKnowledge.tsx @@ -36,7 +36,7 @@ const InfrastructureKnowledge = ({ infrastructure }: { infrastructure: Infrastru <> } /> diff --git a/opencti-platform/opencti-front/src/private/components/techniques/narratives/Root.tsx b/opencti-platform/opencti-front/src/private/components/techniques/narratives/Root.tsx index 6a2ab8206e60..3352e5e28292 100644 --- a/opencti-platform/opencti-front/src/private/components/techniques/narratives/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/techniques/narratives/Root.tsx @@ -115,7 +115,7 @@ const RootNarrative = ({ narrativeId, queryRef }: RootNarrativeProps) => { 'observables', 'sightings', ]} - queryRef={narrative} + data={narrative} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/threats/campaigns/Root.tsx b/opencti-platform/opencti-front/src/private/components/threats/campaigns/Root.tsx index c3be18cd0f08..c09c217ccc20 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/campaigns/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/threats/campaigns/Root.tsx @@ -124,7 +124,7 @@ const RootCampaign = ({ campaignId, queryRef }: RootCampaignProps) => { 'infrastructures', 'sightings', ]} - queryRef={campaign} + data={campaign} attribution={['Intrusion-Set', 'Threat-Actor-Individual', 'Threat-Actor-Group']} /> } diff --git a/opencti-platform/opencti-front/src/private/components/threats/intrusion_sets/Root.tsx b/opencti-platform/opencti-front/src/private/components/threats/intrusion_sets/Root.tsx index 38d7b71e433d..44f4fcde0a95 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/intrusion_sets/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/threats/intrusion_sets/Root.tsx @@ -130,7 +130,7 @@ const RootIntrusionSet = ({ intrusionSetId, queryRef }: RootIntrusionSetProps) = 'infrastructures', 'sightings', ]} - queryRef={intrusionSet} + data={intrusionSet} attribution={['Threat-Actor-Individual', 'Threat-Actor-Group']} /> } diff --git a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx index 9174abeb05d5..fc090a35f549 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx @@ -128,7 +128,7 @@ const RootThreatActorGroup = ({ queryRef, threatActorGroupId }: RootThreatActorG 'infrastructures', 'sightings', ]} - queryRef={threatActorGroup} + data={threatActorGroup} /> } /> diff --git a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx index c6a9d0602a0f..38a8b08c9759 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx @@ -141,7 +141,7 @@ const RootThreatActorIndividualComponent = ({ 'sightings', 'countries', ]} - queryRef={threatActorIndividual} + data={threatActorIndividual} /> } /> From 20bcedf8798a33e78a9e094c10a0663bc32aaece Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Thu, 9 Jan 2025 10:29:55 +0100 Subject: [PATCH 08/15] [frontend] fix variant case (#8115) --- .../common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx index 63f33bfe3125..57fa797e4dda 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx @@ -50,6 +50,7 @@ const stixCoreObjectKnowledgeBarFragment = graphql` "targets" "compromises" "located-at" + "variant-of" ] ) { label From 62e2a430ef819e734de32b2df776d645efb2c77b Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Thu, 30 Jan 2025 15:46:39 +0100 Subject: [PATCH 09/15] [frontend] refactor: split related to fragment distribution (#8115) --- .../StixCoreObjectKnowledgeBar.jsx | 96 ++++++++++--------- 1 file changed, 53 insertions(+), 43 deletions(-) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx index 57fa797e4dda..acbe18eb502f 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx @@ -56,6 +56,15 @@ const stixCoreObjectKnowledgeBarFragment = graphql` label value } + # distribution of entities with "related to" relationship + relationshipsRelatedToDistribution: stixCoreRelationshipsDistribution( + field: "entity_type" + operation: count + relationship_type: [ "related-to" ] + ) { + label + value + } # distribution for observable and indicator type stixCoreObjectsDistribution( field: "entity_type", @@ -64,11 +73,6 @@ const stixCoreObjectKnowledgeBarFragment = graphql` label value } - relatedEntities: stixCoreRelationships(relationship_type: "related-to") { - pageInfo { - globalCount - } - } } `; @@ -83,7 +87,7 @@ const StixCoreObjectKnowledgeBar = ({ const location = useLocation(); const { bannerSettings, schema } = useAuth(); const isInAvailableSection = (sections) => availableSections.some((filter) => sections.includes(filter)); - const { relationshipsWithoutRelatedToDistribution, stixCoreObjectsDistribution, relatedEntities } = useFragment( + const { relationshipsWithoutRelatedToDistribution, relationshipsRelatedToDistribution, stixCoreObjectsDistribution } = useFragment( stixCoreObjectKnowledgeBarFragment, data, ); @@ -93,20 +97,26 @@ const StixCoreObjectKnowledgeBar = ({ ? objectsDistribution.reduce((acc, item) => ({ ...acc, [item.label]: item }), {}) : {}); - const statisticsRelationship = indexEntities(relationshipsWithoutRelatedToDistribution); + const statisticsWithoutRelatedToRelationship = indexEntities(relationshipsWithoutRelatedToDistribution); + const statisticsRelatedToRelationship = indexEntities(relationshipsRelatedToDistribution); const statisticsCoreObjects = indexEntities(stixCoreObjectsDistribution); - const sumEntitiesByKeys = (keys, stats) => keys - .map((key) => stats[key]?.value || 0) - .reduce((acc, val) => acc + val, 0); + const sumEntitiesByKeys = (stats, keys) => { + if (keys) { + return keys + .map((key) => stats[key]?.value || 0) + .reduce((acc, val) => acc + val, 0); + } + return Object.values(stats).reduce((sum, { value }) => sum + value, 0); + }; - const statisticsThreats = sumEntitiesByKeys(['Threat-Actor-Individual', 'Threat-Actor-Group', 'Intrusion-Set', 'Campaign', 'Incident'], statisticsRelationship); - const statisticsThreatActors = sumEntitiesByKeys(['Threat-Actor-Individual', 'Threat-Actor-Group'], statisticsRelationship); - const statisticsVictims = sumEntitiesByKeys(['Sector', 'Organization', 'Individual', 'Region', 'Country', 'City', 'Position', 'Administrative-Area'], statisticsRelationship); - const statisticsAttributions = sumEntitiesByKeys(attribution ?? [], statisticsRelationship); - const statisticsLocations = sumEntitiesByKeys(['Region', 'Country', 'City', 'Position', 'Administrative-Area'], statisticsRelationship); - const statisticsObservables = sumEntitiesByKeys([...schema.scos.map((s) => s.id), 'Stixfile', 'Ipv4-Addr', 'Ipv6-Addr'], statisticsCoreObjects); - const statisticsRelatedEntities = relatedEntities ? relatedEntities.pageInfo.globalCount : 0; + const statisticsThreats = sumEntitiesByKeys(statisticsWithoutRelatedToRelationship, ['Threat-Actor-Individual', 'Threat-Actor-Group', 'Intrusion-Set', 'Campaign', 'Incident']); + const statisticsThreatActors = sumEntitiesByKeys(statisticsWithoutRelatedToRelationship, ['Threat-Actor-Individual', 'Threat-Actor-Group']); + const statisticsVictims = sumEntitiesByKeys(statisticsWithoutRelatedToRelationship, ['Event', 'System', 'Sector', 'Organization', 'Individual', 'Region', 'Country', 'City', 'Position', 'Administrative-Area']); + const statisticsAttributions = sumEntitiesByKeys(statisticsWithoutRelatedToRelationship, attribution ?? []); + const statisticsLocations = sumEntitiesByKeys(statisticsWithoutRelatedToRelationship, ['Region', 'Country', 'City', 'Position', 'Administrative-Area']); + const statisticsObservables = sumEntitiesByKeys(statisticsRelatedToRelationship, [...schema.scos.map((s) => s.id), 'Stixfile', 'Ipv4-Addr', 'Ipv6-Addr']); + const statisticsRelatedEntities = sumEntitiesByKeys(statisticsRelatedToRelationship); return ( - 0 ? ` (${n(statisticsRelationship.Sector.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Sector.value)})` : ''}`} /> )} {availableSections.includes('regions') && ( @@ -170,7 +180,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Region.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Region.value)})` : ''}`} /> )} {availableSections.includes('countries') && ( @@ -186,7 +196,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Country.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Country.value)})` : ''}`} /> )} {availableSections.includes('areas') && ( @@ -200,7 +210,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship['Administrative-Area'].value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship['Administrative-Area'].value)})` : ''}`} /> )} {availableSections.includes('cities') && ( @@ -214,7 +224,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.City.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.City.value)})` : ''}`} /> )} {availableSections.includes('organizations') && ( @@ -230,7 +240,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Organization.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Organization.value)})` : ''}`} /> )} {availableSections.includes('individuals') && ( @@ -246,7 +256,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Individual.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Individual.value)})` : ''}`} /> )} {availableSections.includes('locations') && ( @@ -295,7 +305,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Sector.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Sector.value)})` : ''}`} /> )} {availableSections.includes('regions') && ( @@ -309,7 +319,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Region.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Region.value)})` : ''}`} /> )} {availableSections.includes('countries') && ( @@ -325,7 +335,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Country.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Country.value)})` : ''}`} /> )} {availableSections.includes('areas') && ( @@ -339,7 +349,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship['Administrative-Area'].value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship['Administrative-Area'].value)})` : ''}`} /> )} {availableSections.includes('cities') && ( @@ -353,7 +363,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.City.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.City.value)})` : ''}`} /> )} {availableSections.includes('locations') && ( @@ -385,7 +395,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Organization.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Organization.value)})` : ''}`} /> )} {availableSections.includes('individuals') && ( @@ -401,7 +411,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Individual.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Individual.value)})` : ''}`} /> )} {availableSections.includes('used_tools') && ( @@ -512,7 +522,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship['Intrusion-Set'].value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship['Intrusion-Set'].value)})` : ''}`} /> )} {availableSections.includes('campaigns') && ( @@ -526,7 +536,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Campaign.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Campaign.value)})` : ''}`} /> )} @@ -558,7 +568,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Malware.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Malware.value)})` : ''}`} /> )} {availableSections.includes('malwares') && ( @@ -572,7 +582,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Malware.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Malware.value)})` : ''}`} /> )} {availableSections.includes('channels') && ( @@ -586,7 +596,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Channel.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Channel.value)})` : ''}`} /> )} {availableSections.includes('tools') && ( @@ -600,7 +610,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Tool.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Tool.value)})` : ''}`} /> )} {availableSections.includes('vulnerabilities') && ( @@ -616,7 +626,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Vulnerability.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Vulnerability.value)})` : ''}`} /> )} @@ -644,7 +654,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship['Attack-Pattern'].value)})` : ''}`} /> + 0 ? ` (${n(statisticsCoreObjects['Attack-Pattern'].value)})` : ''}`} /> )} {availableSections.includes('narratives') && ( @@ -660,7 +670,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Narrative.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Narrative.value)})` : ''}`} /> )} @@ -725,7 +735,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Infrastructure.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Infrastructure.value)})` : ''}`} /> )} @@ -749,7 +759,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship.Incident.value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Incident.value)})` : ''}`} /> )} {availableSections.includes('observed_data') && ( @@ -765,7 +775,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsRelationship['Observed-Data'].value)})` : ''}`} /> + 0 ? ` (${n(statisticsWithoutRelatedToRelationship['Observed-Data'].value)})` : ''}`} /> )} {availableSections.includes('sightings') && ( From a40799d95da5eeea7d514e21f055373834d452e2 Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Thu, 30 Jan 2025 15:49:38 +0100 Subject: [PATCH 10/15] [frontend] fix incidents attribution (#8115) --- .../src/private/components/events/incidents/Root.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx b/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx index c2475b54d50b..6cf666b89d7a 100644 --- a/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/events/incidents/Root.tsx @@ -121,6 +121,7 @@ const RootIncidentComponent = ({ queryRef }) => { 'observables', ]} data={incident} + attribution={['Threat-Actor-Individual', 'Threat-Actor-Group', 'Intrusion-Set', 'Campaign']} /> } /> From 7b435d1d930ad4ade083a12f5a2bbddd3e3dc2cc Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Thu, 30 Jan 2025 18:18:56 +0100 Subject: [PATCH 11/15] [frontend] fix log (#8115) --- .../StixCoreRelationshipStixCoreRelationshipsLines.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipStixCoreRelationshipsLines.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipStixCoreRelationshipsLines.jsx index fcbc8b72ff4d..081552b49869 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipStixCoreRelationshipsLines.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_relationships/StixCoreRelationshipStixCoreRelationshipsLines.jsx @@ -61,7 +61,7 @@ class StixCoreRelationshipStixCoreRelationshipsLinesContainer extends Component > From 80896286353f3855d9bcf9256db1adae592c93f9 Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Thu, 30 Jan 2025 18:40:52 +0100 Subject: [PATCH 12/15] [frontend] fix related, threat exception (#8115) --- .../StixCoreObjectKnowledgeBar.jsx | 19 +++++++++++-------- .../threats/threat_actors_group/Root.tsx | 9 ++++++--- .../ThreatActorGroupKnowledge.jsx | 5 +++-- .../threats/threat_actors_individual/Root.tsx | 9 ++++++--- .../ThreatActorIndividualKnowledge.tsx | 4 +++- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx index acbe18eb502f..883cd75e57e5 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx @@ -33,7 +33,10 @@ const useStyles = makeStyles((theme) => ({ })); const stixCoreObjectKnowledgeBarFragment = graphql` - fragment StixCoreObjectKnowledgeBar_stixCoreObject on StixCoreObject { + fragment StixCoreObjectKnowledgeBar_stixCoreObject on StixCoreObject + @argumentDefinitions( + relatedRelationshipTypes: { type: "[String]", defaultValue: ["related-to"] } + ) { # distribution of entities without "related to" relationship relationshipsWithoutRelatedToDistribution: stixCoreRelationshipsDistribution( field: "entity_type" @@ -56,11 +59,11 @@ const stixCoreObjectKnowledgeBarFragment = graphql` label value } - # distribution of entities with "related to" relationship - relationshipsRelatedToDistribution: stixCoreRelationshipsDistribution( + # distribution of entities with relatedRelationshipTypes ("related to" relationship by default) + relationshipsRelatedDistribution: stixCoreRelationshipsDistribution( field: "entity_type" operation: count - relationship_type: [ "related-to" ] + relationship_type: $relatedRelationshipTypes ) { label value @@ -87,7 +90,7 @@ const StixCoreObjectKnowledgeBar = ({ const location = useLocation(); const { bannerSettings, schema } = useAuth(); const isInAvailableSection = (sections) => availableSections.some((filter) => sections.includes(filter)); - const { relationshipsWithoutRelatedToDistribution, relationshipsRelatedToDistribution, stixCoreObjectsDistribution } = useFragment( + const { relationshipsWithoutRelatedToDistribution, relationshipsRelatedDistribution, stixCoreObjectsDistribution } = useFragment( stixCoreObjectKnowledgeBarFragment, data, ); @@ -98,7 +101,7 @@ const StixCoreObjectKnowledgeBar = ({ : {}); const statisticsWithoutRelatedToRelationship = indexEntities(relationshipsWithoutRelatedToDistribution); - const statisticsRelatedToRelationship = indexEntities(relationshipsRelatedToDistribution); + const statisticsRelatedRelationship = indexEntities(relationshipsRelatedDistribution); const statisticsCoreObjects = indexEntities(stixCoreObjectsDistribution); const sumEntitiesByKeys = (stats, keys) => { @@ -115,8 +118,8 @@ const StixCoreObjectKnowledgeBar = ({ const statisticsVictims = sumEntitiesByKeys(statisticsWithoutRelatedToRelationship, ['Event', 'System', 'Sector', 'Organization', 'Individual', 'Region', 'Country', 'City', 'Position', 'Administrative-Area']); const statisticsAttributions = sumEntitiesByKeys(statisticsWithoutRelatedToRelationship, attribution ?? []); const statisticsLocations = sumEntitiesByKeys(statisticsWithoutRelatedToRelationship, ['Region', 'Country', 'City', 'Position', 'Administrative-Area']); - const statisticsObservables = sumEntitiesByKeys(statisticsRelatedToRelationship, [...schema.scos.map((s) => s.id), 'Stixfile', 'Ipv4-Addr', 'Ipv6-Addr']); - const statisticsRelatedEntities = sumEntitiesByKeys(statisticsRelatedToRelationship); + const statisticsObservables = sumEntitiesByKeys(statisticsRelatedRelationship, [...schema.scos.map((s) => s.id), 'Stixfile', 'Ipv4-Addr', 'Ipv6-Addr']); + const statisticsRelatedEntities = sumEntitiesByKeys(statisticsRelatedRelationship); return ( @@ -223,7 +225,7 @@ const RootThreatActorGroup = ({ queryRef, threatActorGroupId }: RootThreatActorG path="/knowledge/*" element={
- +
} /> @@ -272,6 +274,7 @@ const Root = () => { const { threatActorGroupId } = useParams() as { threatActorGroupId: string; }; const queryRef = useQueryLoading(ThreatActorGroupQuery, { id: threatActorGroupId, + relatedRelationshipTypes: THREAT_ACTOR_GROUP_RELATED_RELATIONSHIP_TYPES, }); return ( diff --git a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/ThreatActorGroupKnowledge.jsx b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/ThreatActorGroupKnowledge.jsx index b1733115a14a..341764a0f753 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/ThreatActorGroupKnowledge.jsx +++ b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/ThreatActorGroupKnowledge.jsx @@ -14,7 +14,7 @@ import EntityStixCoreRelationshipsStixCyberObservable from '../../common/stix_co class ThreatActorGroupKnowledgeComponent extends Component { render() { - const { threatActorGroup } = this.props; + const { threatActorGroup, relatedRelationshipTypes } = this.props; const link = `/dashboard/threats/threat_actors_group/${threatActorGroup.id}/knowledge`; return ( <> @@ -52,7 +52,7 @@ class ThreatActorGroupKnowledgeComponent extends Component { element={ @@ -237,7 +239,7 @@ const RootThreatActorIndividualComponent = ({ path="/knowledge/*" element={
- +
} /> @@ -290,6 +292,7 @@ const Root = () => { ThreatActorIndividualQuery, { id: threatActorIndividualId, + relatedRelationshipTypes: THREAT_ACTOR_INDIVIDUAL_RELATED_RELATIONSHIP_TYPES, }, ); return ( diff --git a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/ThreatActorIndividualKnowledge.tsx b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/ThreatActorIndividualKnowledge.tsx index e2b5f3743b6a..ae0e042b0879 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/ThreatActorIndividualKnowledge.tsx +++ b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/ThreatActorIndividualKnowledge.tsx @@ -28,8 +28,10 @@ const threatActorIndividualKnowledgeFragment = graphql` const ThreatActorIndividualKnowledgeComponent = ({ threatActorIndividualData, + relatedRelationshipTypes, }: { threatActorIndividualData: ThreatActorIndividualKnowledge_ThreatActorIndividual$key; + relatedRelationshipTypes: string[] }) => { const threatActorIndividual = useFragment( threatActorIndividualKnowledgeFragment, @@ -71,7 +73,7 @@ const ThreatActorIndividualKnowledgeComponent = ({ element={ Date: Mon, 3 Feb 2025 10:04:51 +0100 Subject: [PATCH 13/15] [frontend] fix lint (#8115) --- .../components/threats/threat_actors_individual/Root.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx index 4e8e5380f468..9af37b7a6374 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_individual/Root.tsx @@ -239,7 +239,10 @@ const RootThreatActorIndividualComponent = ({ path="/knowledge/*" element={
- +
} /> From 37c6d2746c2590490cf022d5e9b9d05d662ee9cc Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Mon, 3 Feb 2025 11:12:49 +0100 Subject: [PATCH 14/15] [frontend] fix arg (#8115) --- .../private/components/threats/threat_actors_group/Root.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx index c0b4448b6405..299b384a440e 100644 --- a/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx +++ b/opencti-platform/opencti-front/src/private/components/threats/threat_actors_group/Root.tsx @@ -225,7 +225,10 @@ const RootThreatActorGroup = ({ queryRef, threatActorGroupId }: RootThreatActorG path="/knowledge/*" element={
- +
} /> From 6245cfa25534824ae8586310826ed55dfde9b3b0 Mon Sep 17 00:00:00 2001 From: FlorianDelemarre Date: Mon, 3 Feb 2025 11:41:15 +0100 Subject: [PATCH 15/15] [frontend] fix entities section and add used tools (#8115) --- .../StixCoreObjectKnowledgeBar.jsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx index 883cd75e57e5..6835a25cdb4f 100644 --- a/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx +++ b/opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectKnowledgeBar.jsx @@ -169,7 +169,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Sector.value)})` : ''}`} /> + 0 ? ` (${n(statisticsCoreObjects.Sector.value)})` : ''}`} /> )} {availableSections.includes('regions') && ( @@ -183,7 +183,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Region.value)})` : ''}`} /> + 0 ? ` (${n(statisticsCoreObjects.Region.value)})` : ''}`} /> )} {availableSections.includes('countries') && ( @@ -199,7 +199,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Country.value)})` : ''}`} /> + 0 ? ` (${n(statisticsCoreObjects.Country.value)})` : ''}`} /> )} {availableSections.includes('areas') && ( @@ -213,7 +213,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsWithoutRelatedToRelationship['Administrative-Area'].value)})` : ''}`} /> + 0 ? ` (${n(statisticsCoreObjects['Administrative-Area'].value)})` : ''}`} /> )} {availableSections.includes('cities') && ( @@ -227,7 +227,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsWithoutRelatedToRelationship.City.value)})` : ''}`} /> + 0 ? ` (${n(statisticsCoreObjects.City.value)})` : ''}`} /> )} {availableSections.includes('organizations') && ( @@ -243,7 +243,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Organization.value)})` : ''}`} /> + 0 ? ` (${n(statisticsCoreObjects.Organization.value)})` : ''}`} /> )} {availableSections.includes('individuals') && ( @@ -259,7 +259,7 @@ const StixCoreObjectKnowledgeBar = ({ - 0 ? ` (${n(statisticsWithoutRelatedToRelationship.Individual.value)})` : ''}`} /> + 0 ? ` (${n(statisticsCoreObjects.Individual.value)})` : ''}`} /> )} {availableSections.includes('locations') && ( @@ -291,7 +291,7 @@ const StixCoreObjectKnowledgeBar = ({ - + 0 ? ` (${n(statisticsCoreObjects.Tool.value)})` : ''}`} /> )}