Skip to content

Commit

Permalink
[backend] Fix name update in upsert on same confidence (#6315)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelHassine authored and Archidoit committed Jun 3, 2024
1 parent e91abba commit 36125c6
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions opencti-platform/opencti-graphql/src/database/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -1384,16 +1384,6 @@ const prepareAttributesForUpdate = async (context, user, instance, elements, ups
value: input.value.map((v) => v.toLowerCase())
};
}
// Specific case for name in aliased entities
// If name change already inside aliases, name must be kep untouched
if (upsert && input.key === NAME_FIELD && isStixObjectAliased(instanceType)) {
const aliasField = resolveAliasesField(instanceType).name;
const normalizeAliases = instance[aliasField] ? instance[aliasField].map((e) => normalizeName(e)) : [];
const name = normalizeName(input.value.at(0));
if ((normalizeAliases).includes(name)) {
return null;
}
}
// Aliases can't have the same name as entity name and an already existing normalized alias
if (input.key === ATTRIBUTE_ALIASES || input.key === ATTRIBUTE_ALIASES_OPENCTI) {
const filteredValues = input.value.filter((e) => normalizeName(e) !== normalizeName(instance.name));
Expand Down Expand Up @@ -1524,7 +1514,7 @@ const updateAttributeRaw = async (context, user, instance, inputs, opts = {}) =>
// If name changing is part of an upsert, the previous name must be copied into aliases
aliases.push(instance.name);
}
const uniqAliases = R.uniqBy((e) => normalizeName(e), aliases);
const uniqAliases = R.uniqBy((e) => normalizeName(e), aliases).filter((a) => a !== askedModificationName);
if (aliasesInput) { // If aliases input also exists
aliasesInput.value = uniqAliases;
} else { // We need to create an extra input getting existing aliases
Expand Down

0 comments on commit 36125c6

Please sign in to comment.