-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8529985
commit 6c2956b
Showing
5 changed files
with
36 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 26 additions & 13 deletions
39
opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation-domain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,40 @@ | ||
import type { AuthContext, AuthUser } from '../../types/user'; | ||
import { type BasicStoreEntityDeleteOperation, ENTITY_TYPE_DELETE_OPERATION } from './deleteOperation-types'; | ||
import { FunctionalError } from '../../config/errors'; | ||
import { elDeleteInstances, elFindByIds } from '../../database/engine'; | ||
import { deleteAllObjectFiles } from '../../database/file-storage'; | ||
import { listEntitiesPaginated, storeLoadById } from '../../database/middleware-loader'; | ||
import { READ_INDEX_DELETED_OBJECTS } from '../../database/utils'; | ||
import type { QueryDeleteOperationsArgs } from '../../generated/graphql'; | ||
import { type BasicStoreEntityDeleteOperation, ENTITY_TYPE_DELETE_OPERATION } from './deleteOperation-types'; | ||
|
||
export interface DeletedElement { | ||
id: string | ||
source_index: string | ||
} | ||
import type { AuthContext, AuthUser } from '../../types/user'; | ||
|
||
export const findById = (context: AuthContext, user: AuthUser, id: string) => { | ||
export const findById = async (context: AuthContext, user: AuthUser, id: string) => { | ||
return storeLoadById<BasicStoreEntityDeleteOperation>(context, user, id, ENTITY_TYPE_DELETE_OPERATION); | ||
}; | ||
|
||
export const findAll = (context: AuthContext, user: AuthUser, args: QueryDeleteOperationsArgs) => { | ||
export const findAll = async (context: AuthContext, user: AuthUser, args: QueryDeleteOperationsArgs) => { | ||
return listEntitiesPaginated<BasicStoreEntityDeleteOperation>(context, user, [ENTITY_TYPE_DELETE_OPERATION], args); | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const restoreDelete = (context: AuthContext, user: AuthUser, id: string) => { | ||
export const restoreDelete = async (context: AuthContext, user: AuthUser, id: string) => { | ||
throw new Error('Restore delete not implemented'); | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const completeDelete = (context: AuthContext, user: AuthUser, id: string) => { | ||
throw new Error('Complete delete not implemented'); | ||
export const completeDelete = async (context: AuthContext, user: AuthUser, id: string) => { | ||
const deleteOperation = await findById(context, user, id); | ||
if (!deleteOperation) { | ||
throw FunctionalError(`Delete operation ${id} cannot be found`); | ||
} | ||
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); | ||
} | ||
// delete elements & delete operation | ||
await elDeleteInstances([...deletedElements]); | ||
await elDeleteInstances([deleteOperation]); | ||
return id; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
opencti-platform/opencti-graphql/src/modules/deleteOperation/deleteOperation-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters