Projects STRLCPY opencti Commits c8e45f20
🤬
  • [frontend] Add knowledge component [API] Add data source ref to data component

  • Loading...
  • Romuald Lemesle committed 1 year ago
    c8e45f20
    1 parent af9def59
  • ■ ■ ■ ■ ■ ■
    opencti-platform/opencti-front/src/private/components/nav/TopMenuDataComponent.tsx
    skipped 75 lines
    76 76   >
    77 77   {t('Overview')}
    78 78   </Button>
     79 + <Button
     80 + component={Link}
     81 + to={`/dashboard/techniques/data_components/${dataComponentId}/knowledge`}
     82 + variant={
     83 + location.pathname.includes(
     84 + `/dashboard/techniques/data_components/${dataComponentId}/knowledge`,
     85 + )
     86 + ? 'contained'
     87 + : 'text'
     88 + }
     89 + size="small"
     90 + color={
     91 + location.pathname.includes(
     92 + `/dashboard/techniques/data_components/${dataComponentId}/knowledge`,
     93 + )
     94 + ? 'secondary'
     95 + : 'primary'
     96 + }
     97 + classes={{ root: classes.button }}
     98 + >
     99 + {t('Knowledge')}
     100 + </Button>
    79 101   <Security needs={[KNOWLEDGE_KNUPLOAD, KNOWLEDGE_KNGETEXPORT]}>
    80 102   <Button
    81 103   component={Link}
    skipped 45 lines
  • ■ ■ ■ ■ ■
    opencti-platform/opencti-front/src/private/components/techniques/data_components/Root.tsx
    skipped 37 lines
    38 38   id
    39 39   name
    40 40   ...DataComponent_dataComponent
     41 + ...DataComponentKnowledge_dataComponent
    41 42   ...FileImportViewer_entity
    42 43   ...FileExportViewer_entity
    43 44   ...FileExternalReferencesViewer_entity
    skipped 57 lines
    101 102   render={(routeProps) => (
    102 103   <DataComponentKnowledge
    103 104   {...routeProps}
    104  - dataComponent={props.dataComponent}
     105 + data={props.dataComponent}
     106 + enableReferences={props.settings.platform_enable_reference?.includes(
     107 + 'Data-Component',
     108 + )}
    105 109   />
    106 110   )}
    107 111   />
    skipped 61 lines
  • ■ ■ ■ ■ ■
    opencti-platform/opencti-front/src/schema/relay.schema.graphql
    skipped 8639 lines
    8640 8640   name: name_String_NotNull_minLength_2!
    8641 8641   description: String!
    8642 8642   aliases: [String]
     8643 + dataSource: String
    8643 8644  }
    8644 8645   
    8645 8646  type DataSource implements BasicObject & StixObject & StixCoreObject & StixDomainObject {
    skipped 104 lines
  • ■ ■ ■ ■ ■ ■
    opencti-platform/opencti-graphql/src/database/stix.ts
    skipped 1196 lines
    1197 1197   return R.includes(relationshipType, targetRelations);
    1198 1198  };
    1199 1199   
     1200 +export const CHECK_META_RELATIONSHIP_VALUES: { [k: string]: (fromType: string, toType: string) => boolean } = {
     1201 + [RELATION_GRANTED_TO]: (fromType, toType) => !(fromType === ENTITY_TYPE_EVENT || isStixDomainObjectIdentity(fromType)
     1202 + || isStixDomainObjectLocation(fromType)) && ENTITY_TYPE_IDENTITY_ORGANIZATION === toType,
     1203 + [RELATION_CREATED_BY]: (fromType, toType) => isStixDomainObjectIdentity(toType),
     1204 + [RELATION_OBJECT_MARKING]: (fromType, toType) => ENTITY_TYPE_MARKING_DEFINITION === toType,
     1205 + [RELATION_OBJECT]: (fromType, toType) => isStixDomainObjectContainer(fromType),
     1206 + [RELATION_OBJECT_LABEL]: (fromType, toType) => toType === ENTITY_TYPE_LABEL,
     1207 + [RELATION_EXTERNAL_REFERENCE]: (fromType, toType) => toType === ENTITY_TYPE_EXTERNAL_REFERENCE,
     1208 + [RELATION_KILL_CHAIN_PHASE]: (fromType, toType) => toType === ENTITY_TYPE_KILL_CHAIN_PHASE
     1209 +};
     1210 + 
    1200 1211  export const checkMetaRelationship = (fromType: string, toType: string, relationshipType: string): boolean => {
    1201  - switch (relationshipType) {
    1202  - case RELATION_GRANTED_TO:
    1203  - return !(fromType === ENTITY_TYPE_EVENT || isStixDomainObjectIdentity(fromType) || isStixDomainObjectLocation(fromType))
    1204  - && ENTITY_TYPE_IDENTITY_ORGANIZATION === toType;
    1205  - case RELATION_CREATED_BY:
    1206  - return isStixDomainObjectIdentity(toType);
    1207  - case RELATION_OBJECT_MARKING:
    1208  - return ENTITY_TYPE_MARKING_DEFINITION === toType;
    1209  - case RELATION_OBJECT:
    1210  - return isStixDomainObjectContainer(fromType);
    1211  - case RELATION_OBJECT_LABEL:
    1212  - return toType === ENTITY_TYPE_LABEL;
    1213  - case RELATION_EXTERNAL_REFERENCE:
    1214  - return toType === ENTITY_TYPE_EXTERNAL_REFERENCE;
    1215  - case RELATION_KILL_CHAIN_PHASE:
    1216  - return toType === ENTITY_TYPE_KILL_CHAIN_PHASE;
    1217  - default:
    1218  - return false;
     1212 + const checkMetaRelationshipFn = CHECK_META_RELATIONSHIP_VALUES[relationshipType];
     1213 + if (checkMetaRelationshipFn) {
     1214 + return checkMetaRelationshipFn(fromType, toType);
    1219 1215   }
     1216 + return false;
    1220 1217  };
    1221 1218   
  • ■ ■ ■ ■ ■
    opencti-platform/opencti-graphql/src/generated/graphql.ts
    skipped 2710 lines
    2711 2711   confidence?: InputMaybe<Scalars['Int']>;
    2712 2712   created?: InputMaybe<Scalars['DateTime']>;
    2713 2713   createdBy?: InputMaybe<Scalars['String']>;
     2714 + dataSource?: InputMaybe<Scalars['String']>;
    2714 2715   description: Scalars['String'];
    2715 2716   externalReferences?: InputMaybe<Array<InputMaybe<Scalars['String']>>>;
    2716 2717   lang?: InputMaybe<Scalars['String']>;
    skipped 24188 lines
  • ■ ■ ■ ■ ■
    opencti-platform/opencti-graphql/src/modules/dataComponent/dataComponent-domain.ts
    1  -import { createEntity, storeLoadById } from '../../database/middleware';
     1 +import { batchLoadThroughGetTo, createEntity, storeLoadById } from '../../database/middleware';
    2 2  import { listEntitiesPaginated } from '../../database/middleware-loader';
    3 3  import type { AuthContext, AuthUser } from '../../types/user';
    4 4  import type { BasicStoreEntityDataComponent } from './dataComponent-types';
     5 +import { ENTITY_TYPE_DATA_COMPONENT } from './dataComponent-types';
    5 6  import type { DataComponentAddInput, QueryDataComponentsArgs } from '../../generated/graphql';
    6 7  import { notify } from '../../database/redis';
    7 8  import { BUS_TOPICS } from '../../config/conf';
    8 9  import { ABSTRACT_STIX_DOMAIN_OBJECT } from '../../schema/general';
    9  -import { ENTITY_TYPE_DATA_COMPONENT } from './dataComponent-types';
     10 +import { ENTITY_TYPE_DATA_SOURCE } from '../dataSource/dataSource-types';
     11 + 
     12 +export const RELATION_DATA_SOURCE = 'data-source';
     13 +export const INPUT_DATA_SOURCE = 'dataSource';
    10 14   
    11 15  export const findById = (context: AuthContext, user: AuthUser, dataComponentId: string): BasicStoreEntityDataComponent => {
    12 16   return storeLoadById(context, user, dataComponentId, ENTITY_TYPE_DATA_COMPONENT) as unknown as BasicStoreEntityDataComponent;
    skipped 8 lines
    21 25   return notify(BUS_TOPICS[ABSTRACT_STIX_DOMAIN_OBJECT].ADDED_TOPIC, created, user);
    22 26  };
    23 27   
     28 +export const batchDataSource = async (context: AuthContext, user: AuthUser, dataComponentId: string) => {
     29 + return batchLoadThroughGetTo(context, user, dataComponentId, RELATION_DATA_SOURCE, ENTITY_TYPE_DATA_SOURCE);
     30 +};
     31 + 
  • ■ ■ ■ ■ ■
    opencti-platform/opencti-graphql/src/modules/dataComponent/dataComponent-resolver.ts
    1 1  import type { Resolvers } from '../../generated/graphql';
    2 2  import { buildRefRelationKey } from '../../schema/general';
    3 3  import { RELATION_CREATED_BY, RELATION_OBJECT_LABEL, RELATION_OBJECT_MARKING } from '../../schema/stixMetaRelationship';
    4  -import { dataComponentAdd, findAll, findById } from './dataComponent-domain';
     4 +import { batchDataSource, dataComponentAdd, findAll, findById } from './dataComponent-domain';
    5 5  import {
    6 6   stixDomainObjectAddRelation,
    7 7   stixDomainObjectCleanContext,
    skipped 2 lines
    10 10   stixDomainObjectEditContext,
    11 11   stixDomainObjectEditField
    12 12  } from '../../domain/stixDomainObject';
     13 +import { batchLoader } from '../../database/middleware';
     14 + 
     15 +const dataSourceLoader = batchLoader(batchDataSource);
    13 16   
    14 17  const dataComponentResolvers: Resolvers = {
    15 18   Query: {
    skipped 4 lines
    20 23   createdBy: buildRefRelationKey(RELATION_CREATED_BY),
    21 24   markedBy: buildRefRelationKey(RELATION_OBJECT_MARKING),
    22 25   labelledBy: buildRefRelationKey(RELATION_OBJECT_LABEL),
    23  - // dataSource: buildRefRelationKey(RELATION_DATA_SOURCE),
     26 + },
     27 + DataComponent: {
     28 + dataSource: (dataComponent, _, context) => dataSourceLoader.load(dataComponent.id, context, context.user),
    24 29   },
    25 30   Mutation: {
    26 31   dataComponentAdd: (_: any, { input }: any, context: any) => {
    skipped 25 lines
  • ■ ■ ■ ■
    opencti-platform/opencti-graphql/src/modules/dataComponent/dataComponent.graphql
    skipped 158 lines
    159 159   name: String! @constraint(minLength: 2)
    160 160   description: String!
    161 161   aliases: [String]
    162  -# data_source: String
     162 + dataSource: String
    163 163  }
    164 164   
    165 165  type Mutation {
    skipped 9 lines
  • ■ ■ ■ ■ ■
    opencti-platform/opencti-graphql/src/modules/dataComponent/dataComponent.ts
    skipped 3 lines
    4 4  import { ENTITY_TYPE_ATTACK_PATTERN } from '../../schema/stixDomainObject';
    5 5  import { NAME_FIELD, normalizeName } from '../../schema/identifier';
    6 6  import type { StoreEntityDataComponent } from './dataComponent-types';
     7 +import { ENTITY_TYPE_DATA_COMPONENT } from './dataComponent-types';
    7 8  import dataComponentResolvers from './dataComponent-resolver';
    8 9  import convertDataComponentToStix from './dataComponent-converter';
    9 10  import { RELATION_DETECTS } from '../../schema/stixCoreRelationship';
    10 11  import { REL_EXTENDED } from '../../database/stix';
    11  -import { ENTITY_TYPE_DATA_COMPONENT } from './dataComponent-types';
     12 +import { INPUT_DATA_SOURCE, RELATION_DATA_SOURCE } from './dataComponent-domain';
     13 +import { ENTITY_TYPE_DATA_SOURCE } from '../dataSource/dataSource-types';
    12 14   
    13 15  const DATA_COMPONENT_DEFINITION: ModuleDefinition<StoreEntityDataComponent> = {
    14 16   type: {
    skipped 39 lines
    54 56   type: REL_EXTENDED
    55 57   }
    56 58   ]
     59 + }
     60 + ],
     61 + relationsRefs: [
     62 + {
     63 + input: INPUT_DATA_SOURCE,
     64 + relation: RELATION_DATA_SOURCE,
     65 + checker: (fromType, toType) => toType === ENTITY_TYPE_DATA_SOURCE
    57 66   }
    58 67   ],
    59 68   converter: convertDataComponentToStix
    skipped 4 lines
  • ■ ■ ■ ■ ■ ■
    opencti-platform/opencti-graphql/src/types/module.ts
    skipped 6 lines
    7 7  } from '../schema/stixDomainObject';
    8 8  import { registerGraphqlSchema } from '../graphql/schema';
    9 9  import { registerModelIdentifier } from '../schema/identifier';
    10  -import { schemaTypes } from '../schema/general';
     10 +import { schemaTypes, STIX_META_RELATIONSHIPS_INPUTS } from '../schema/general';
    11 11  import { registerStixDomainConverter } from '../database/stix-converter';
    12 12  import {
    13 13   booleanAttributes,
    skipped 4 lines
    18 18  } from '../schema/fieldDataAdapter';
    19 19  import { STIX_CORE_RELATIONSHIPS } from '../schema/stixCoreRelationship';
    20 20  import {
     21 + CHECK_META_RELATIONSHIP_VALUES,
    21 22   RelationDefinition,
    22 23   stixCoreRelationshipsMapping as coreRels,
    23 24  } from '../database/stix';
     25 +import { STIX_EXTERNAL_META_RELATIONSHIPS, STIX_META_RELATION_TO_FIELD } from '../schema/stixMetaRelationship';
     26 +import { RELATION_DATA_SOURCE } from '../modules/dataComponent/dataComponent-domain';
    24 27   
    25 28  export type AttrType = 'string' | 'date' | 'numeric' | 'boolean' | 'dictionary' | 'json';
    26 29  export interface ModuleDefinition<T extends StoreEntity> {
    skipped 25 lines
    52 55   name: string;
    53 56   targets: Array<RelationDefinition>;
    54 57   }>;
     58 + relationsRefs: Array<{
     59 + input: string;
     60 + relation: string;
     61 + checker: (fromType: string, toType: string) => boolean;
     62 + }>;
    55 63   converter: ConvertFn<T>;
    56 64  }
    57 65   
    skipped 44 lines
    102 110   const key: `${string}_${string}` = `${definition.type.name}_${target.name}`;
    103 111   coreRels[key] = [...(coreRels[key] ?? []), { name: source.name, type: target.type }];
    104 112   });
     113 + });
     114 + // Register relations ref
     115 + definition.relationsRefs?.forEach((source) => {
     116 + STIX_META_RELATIONSHIPS_INPUTS.push(source.input);
     117 + STIX_EXTERNAL_META_RELATIONSHIPS.push(source.relation);
     118 + STIX_META_RELATION_TO_FIELD[source.relation] = source.input;
     119 + CHECK_META_RELATIONSHIP_VALUES[RELATION_DATA_SOURCE] = source.checker;
    105 120   });
    106 121  };
    107 122   
Please wait...
Page is in error, reload to recover