New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[backend] Improve handling of refs relationships (#4476) #5004
Conversation
@@ -48,14 +57,36 @@ export const isDatable = (entityType, relationshipType) => { | |||
}; | |||
|
|||
// Mutation | |||
|
|||
// @Deprecated method. | |||
// updateField must be directly used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not find this method in the project. What are you referring to ?
Is it a TODO ?
if (entity) { // Entity can be null for global | ||
if (entity.creator_id) { | ||
contextData.creator_ids = Array.isArray(entity.creator_id) ? entity.creator_id : [entity.creator_id]; | ||
} | ||
if (entity[RELATION_GRANTED_TO]) { | ||
contextData.granted_refs_ids = entity[RELATION_GRANTED_TO]; | ||
} | ||
if (entity[RELATION_OBJECT_MARKING]) { | ||
contextData.object_marking_refs_ids = entity[RELATION_OBJECT_MARKING]; | ||
} | ||
if (entity[RELATION_CREATED_BY]) { | ||
contextData.created_by_ref_id = entity[RELATION_CREATED_BY]; | ||
} | ||
if (entity[RELATION_OBJECT_LABEL]) { | ||
contextData.labels_ids = entity[RELATION_OBJECT_LABEL]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those lines are duplicates from domain/stix.js
.
I took the liberty to refactor both files with a dedicated function reducing the nesting of if
and the code duplication
buildRelationRef(contains, (_: string, toType: string) => [ENTITY_DIRECTORY, ENTITY_HASHED_OBSERVABLE_STIX_FILE].includes(toType)) | ||
]); | ||
schemaRelationsRefDefinition.registerRelationsRef(ENTITY_DOMAIN_NAME, [ | ||
buildRelationRef(resolvesTo, (fromType: string, toType: string) => [ENTITY_DOMAIN_NAME, ENTITY_IPV4_ADDR, ENTITY_IPV6_ADDR].includes(toType)) | ||
buildRelationRef(resolvesTo, (_: string, toType: string) => [ENTITY_DOMAIN_NAME, ENTITY_IPV4_ADDR, ENTITY_IPV6_ADDR].includes(toType)) | ||
]); | ||
schemaRelationsRefDefinition.registerRelationsRef(ENTITY_EMAIL_MESSAGE, [ | ||
buildRelationRef(from, (fromType: string, toType: string) => ENTITY_EMAIL_ADDR === toType), | ||
buildRelationRef(sender, (fromType: string, toType: string) => ENTITY_EMAIL_ADDR === toType), | ||
buildRelationRef(to, (fromType: string, toType: string) => ENTITY_EMAIL_ADDR === toType), | ||
buildRelationRef(cc, (fromType: string, toType: string) => ENTITY_EMAIL_ADDR === toType), | ||
buildRelationRef(bcc, (fromType: string, toType: string) => ENTITY_EMAIL_ADDR === toType), | ||
buildRelationRef(bodyMultipart, (fromType: string, toType: string) => ENTITY_EMAIL_MIME_PART_TYPE === toType), | ||
buildRelationRef(rawEmail, (fromType: string, toType: string) => ENTITY_HASHED_OBSERVABLE_ARTIFACT === toType), | ||
buildRelationRef(from, (_: string, toType: string) => ENTITY_EMAIL_ADDR === toType), | ||
buildRelationRef(sender, (_: string, toType: string) => ENTITY_EMAIL_ADDR === toType), | ||
buildRelationRef(to, (_: string, toType: string) => ENTITY_EMAIL_ADDR === toType), | ||
buildRelationRef(cc, (_: string, toType: string) => ENTITY_EMAIL_ADDR === toType), | ||
buildRelationRef(bcc, (_: string, toType: string) => ENTITY_EMAIL_ADDR === toType), | ||
buildRelationRef(bodyMultipart, (_: string, toType: string) => ENTITY_EMAIL_MIME_PART_TYPE === toType), | ||
buildRelationRef(rawEmail, (_: string, toType: string) => ENTITY_HASHED_OBSERVABLE_ARTIFACT === toType), | ||
]); | ||
schemaRelationsRefDefinition.registerRelationsRef(ENTITY_EMAIL_ADDR, [ | ||
buildRelationRef(belongsTo, (fromType: string, toType: string) => ENTITY_USER_ACCOUNT === toType) | ||
buildRelationRef(belongsTo, (_: string, toType: string) => ENTITY_USER_ACCOUNT === toType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the Checker type is only used in this file, maybe we could update it by removing fromType
from the function arguments ?
See #4476