Skip to content

Commit

Permalink
[backend] move relatedRestrictions in context
Browse files Browse the repository at this point in the history
  • Loading branch information
marieflorescontact committed Jan 6, 2025
1 parent 92bafdc commit 754fe05
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions opencti-platform/opencti-graphql/src/database/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,10 @@ export const buildStixUpdateEvent = (user: AuthUser, previousStix: StixCoreObjec
origin: user.origin,
data: stix,
commit: opts.commit,
relatedRestrictions: opts.relatedRestrictions,
context: {
patch,
reverse_patch: previousPatch
reverse_patch: previousPatch,
relatedRestrictions: opts.relatedRestrictions,
}
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ export const buildHistoryElementsFromEvents = async (context:AuthContext, events
.map((stixId) => grantedRefsResolved.get(stixId))
.filter((o) => isNotEmptyField(o));
}
if (event.data.relatedRestrictions) {
const relatedMarkings = event.data.relatedRestrictions.markings ?? [];
eventMarkingRefs.push(...relatedMarkings);
}
const contextData: HistoryContext = {
id: stix.extensions[STIX_EXT_OCTI].id,
message: event.data.message,
Expand All @@ -126,6 +122,11 @@ export const buildHistoryElementsFromEvents = async (context:AuthContext, events
.map((stixId) => markingsById.get(stixId)?.internal_id)
.filter((o) => isNotEmptyField(o)) as string[];
eventMarkingRefs.push(...previousMarkingRefs);
// Get related restrictions (e.g. markings of added objects in a container)
if (updateEvent.context.relatedRestrictions) {
const relatedMarkings = updateEvent.context.relatedRestrictions.markings ?? [];
eventMarkingRefs.push(...relatedMarkings);
}
}
if (stix.type === STIX_TYPE_RELATION) {
const rel: StixRelation = stix as StixRelation;
Expand Down
2 changes: 1 addition & 1 deletion opencti-platform/opencti-graphql/src/types/event.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ interface StreamDataEvent extends BaseEvent {
origin: Partial<UserOrigin>;
message: string;
data: StixCoreObject
relatedRestrictions?: { markings: string[] };
}

interface UpdateEvent extends StreamDataEvent {
Expand All @@ -54,6 +53,7 @@ interface UpdateEvent extends StreamDataEvent {
context: {
patch: Array<Operation>;
reverse_patch: Array<Operation>;
relatedRestrictions?: { markings: string[] };
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const eventWithRelatedRestriction = {
],
organization_ids: [],
user_metadata: {},
referer: 'http://localhost:3000/dashboard/analyses/reports/e6babfee-aa64-4e3a-9c67-1a163c178ca0/knowledge/graph?zoom=%7B%22k%22%3A0.853929691647981%2C%22x%22%3A21.67720005607563%2C%22y%22%3A-0.5756976120699228%7D&mode3D=false&selectRectangleModeFree=false&selectModeFree=false&selectModeFreeReady=true&modeFixed=false&modeTree=&displayTimeRange=false&selectedTimeRangeInterval=Wed+Dec+04+2024+00%3A00%3A00+GMT%2B0100+%28heure+normale+d%E2%80%99Europe+centrale%29%2CSat+Dec+07+2024+09%3A00%3A00+GMT%2B0100+%28heure+normale+d%E2%80%99Europe+centrale%29&stixCoreObjectsTypes=&markedBy=&createdBy=&width=null&height=null&zoomed=false&keyword=&openCreatedRelation=false'
referer: 'http://localhost:3000/dashboard'
},
data: {
id: 'report--50ddc6fe-2a84-5c9a-904d-f964a94d1ff7',
Expand Down Expand Up @@ -181,11 +181,6 @@ const eventWithRelatedRestriction = {
'identity--e52b2fa3-2af0-5e53-ad38-17d54b3d61cb'
]
},
relatedRestrictions: {
markings: [
'4584aeee-10b6-47a7-808e-603440642285'
]
},
context: {
patch: [
{
Expand All @@ -199,7 +194,12 @@ const eventWithRelatedRestriction = {
op: 'remove',
path: '/object_refs/7'
}
]
],
relatedRestrictions: {
markings: [
'4584aeee-10b6-47a7-808e-603440642285'
]
},
}
}
};
Expand Down

0 comments on commit 754fe05

Please sign in to comment.