Skip to content

Commit

Permalink
[backend] add search on main entity name and fix delete confirm
Browse files Browse the repository at this point in the history
  • Loading branch information
SouadHadjiat committed Apr 4, 2024
1 parent d8a9875 commit 98b3b57
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions opencti-platform/opencti-graphql/src/database/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,7 @@ const BASE_SEARCH_ATTRIBUTES = [
'kill_chain_name',
'definition',
'definition_type',
'main_entity_name', // deletedOperation
];

function processSearch(search, args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ export const completeDelete = async (context: AuthContext, user: AuthUser, id: s
if (!deleteOperation) {
throw FunctionalError(`Delete operation ${id} cannot be found`);
}
// get all deleted elements & main deleted entity (from deleted_objects index)
const mainEntityId = deleteOperation.main_entity_id;
const deletedElementsIds = deleteOperation.deleted_elements.map((el) => el.id);
// get deleted elements (from deleted_objects index)
const deletedElements: any[] = await elFindByIds(context, user, deletedElementsIds, { indices: READ_INDEX_DELETED_OBJECTS }) as any[];
for (let index = 0; index < deletedElements.length; index += 1) {
const element = deletedElements[index];
// delete files
await deleteAllObjectFiles(context, user, element);
const mainDeletedEntity = deletedElements.find((el) => el.internal_id === mainEntityId);
if (mainDeletedEntity) {
// delete main entity files
await deleteAllObjectFiles(context, user, mainDeletedEntity);
}
// delete elements & delete operation
// delete elements
await elDeleteInstances([...deletedElements]);
// finally delete deleteOperation
await elDeleteInstances([deleteOperation]);
return id;
};

0 comments on commit 98b3b57

Please sign in to comment.