Skip to content
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

Merged
merged 3 commits into from Nov 30, 2023

Conversation

richard-julien
Copy link
Member

See #4476

@richard-julien richard-julien marked this pull request as draft November 28, 2023 17:18
@richard-julien richard-julien marked this pull request as ready for review November 28, 2023 21:10
@richard-julien richard-julien added the filigran team use to identify PR from the Filigran team label Nov 28, 2023
@SamuelHassine SamuelHassine merged commit 7c59f84 into master Nov 30, 2023
6 checks passed
@SamuelHassine SamuelHassine deleted the issue/4476 branch November 30, 2023 14:00
@Goumies Goumies restored the issue/4476 branch November 30, 2023 14:48
@Goumies Goumies self-requested a review November 30, 2023 14:49
@@ -48,14 +57,36 @@ export const isDatable = (entityType, relationshipType) => {
};

// Mutation

// @Deprecated method.
// updateField must be directly used
Copy link
Member

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 ?

Comment on lines +101 to +116
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];
}
Copy link
Member

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

Comment on lines +66 to +81
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)
Copy link
Member

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 ?

@Goumies Goumies mentioned this pull request Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filigran team use to identify PR from the Filigran team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants