■ ■ ■ ■ ■ ■
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 | | |