Skip to content

Commit

Permalink
[backend] Use eventId date in iAttributes to prevent loosing valid up…
Browse files Browse the repository at this point in the history
…dates
  • Loading branch information
richard-julien authored and JeremyCloarec committed Feb 4, 2025
1 parent e845f2c commit 1d30541
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions opencti-platform/opencti-graphql/src/database/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,10 @@ const updateAttributeRaw = async (context, user, instance, inputs, opts = {}) =>
};
};

const computeDateFromEventId = (context) => {
return utcDate(parseInt(context.eventId.split('-')[0], 10)).toISOString();
};

export const updateAttributeMetaResolved = async (context, user, initial, inputs, opts = {}) => {
const { locks = [], impactStandardId = true } = opts;
const updates = Array.isArray(inputs) ? inputs : [inputs];
Expand Down Expand Up @@ -2143,7 +2147,7 @@ export const updateAttributeMetaResolved = async (context, user, initial, inputs
const uniqImpactKey = uniqImpactKeys[i];
attributesMap.set(uniqImpactKey, {
name: uniqImpactKey,
updated_at: now(),
updated_at: context.eventId ? computeDateFromEventId(context) : now(),
confidence: confidenceLevelToApply,
user_id: user.internal_id,
});
Expand Down Expand Up @@ -2509,7 +2513,7 @@ const isOutdatedUpdate = (context, element, attributeKey) => {
const { updated_at: lastAttributeUpdateDate } = attributesMap.get(attributeKey) ?? {};
if (lastAttributeUpdateDate) {
try {
const eventDate = utcDate(parseInt(context.eventId.split('-')[0], 10)).toISOString();
const eventDate = computeDateFromEventId(context);
return utcDate(lastAttributeUpdateDate).isAfter(eventDate);
} catch (e) {
logApp.error('Error evaluating event id', { key: attributeKey, event_id: context.eventId });
Expand Down

0 comments on commit 1d30541

Please sign in to comment.