Skip to content

Commit

Permalink
Commit search index after project deletion
Browse files Browse the repository at this point in the history
Fixes DependencyTrack#1605

Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed May 11, 2022
1 parent 768b244 commit 47d81ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -579,16 +579,18 @@ public Project clone(UUID from, String newVersion, boolean includeTags, boolean
/**
* Deletes a Project and all objects dependant on the project.
* @param project the Project to delete
* @param commitIndex specifies if the search index should be committed (an expensive operation)
*/
public void recursivelyDelete(Project project) {
public void recursivelyDelete(final Project project, final boolean commitIndex) {
if (project.getChildren() != null) {
for (final Project child: project.getChildren()) {
recursivelyDelete(child);
recursivelyDelete(child, false);
}
}
pm.getFetchPlan().setDetachmentOptions(FetchPlan.DETACH_LOAD_FIELDS);
final Project result = pm.getObjectById(Project.class, project.getId());
Event.dispatch(new IndexEvent(IndexEvent.Action.DELETE, pm.detachCopy(result)));
commitSearchIndex(commitIndex, Project.class);

deleteAnalysisTrail(project);
deleteViolationAnalysisTrail(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ public Project updateLastBomImport(Project p, Date date, String bomFormat) {
return getProjectQueryManager().updateLastBomImport(p, date, bomFormat);
}

public void recursivelyDelete(Project project) {
getProjectQueryManager().recursivelyDelete(project);
public void recursivelyDelete(final Project project, final boolean commitIndex) {
getProjectQueryManager().recursivelyDelete(project, commitIndex);
}

public ProjectProperty createProjectProperty(final Project project, final String groupName, final String propertyName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ public Response deleteProject(
final Project project = qm.getObjectByUuid(Project.class, uuid, Project.FetchGroup.ALL.name());
if (project != null) {
if (qm.hasAccess(super.getPrincipal(), project)) {
LOGGER.info("Project " + project.toString() + " deletion request by " + super.getPrincipal().getName());
qm.recursivelyDelete(project);
LOGGER.info("Project " + project + " deletion request by " + super.getPrincipal().getName());
qm.recursivelyDelete(project, true);
return Response.status(Response.Status.NO_CONTENT).build();
} else {
return Response.status(Response.Status.FORBIDDEN).entity("Access to the specified project is forbidden").build();
Expand Down

0 comments on commit 47d81ed

Please sign in to comment.