TrashController extends BaseController { @ApiOperation(value = "Used to delete the trash for a specified repository.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The trash for ${storageId}:${repositoryId}' was removed successfully."), @ApiResponse(code = 400, message = "Could not delete the trash for a specified storageId/repositoryId."), @ApiResponse(code = 404, message = "The specified (storageId/repositoryId) does not exist!") }) @PreAuthorize("hasAuthority('MANAGEMENT_DELETE_TRASH')") @DeleteMapping(value = "{storageId}/{repositoryId}", produces = { MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE }) public ResponseEntity delete(@RepositoryMapping Repository repository, @RequestHeader(HttpHeaders.ACCEPT) String accept) throws IOException { final String storageId = repository.getStorage().getId(); final String repositoryId = repository.getId(); try { repositoryManagementService.deleteTrash(storageId, repositoryId); logger.debug("Deleted trash for repository {}.", repositoryId); } catch (ArtifactStorageException e) { String message = "Could not delete the trash for a specified storageId/repositoryId."; logger.error(message, e); return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(getResponseEntityBody(message, accept)); } String message = "The trash for '" + storageId + ":" + repositoryId + "' was removed successfully."; return ResponseEntity.ok(getResponseEntityBody(message, accept)); }  @ApiOperation(value = "Used to delete the trash for a specified repository.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The trash for ${storageId}:${repositoryId}' was removed successfully."), @ApiResponse(code = 400, message = "Could not delete the trash for a specified storageId/repositoryId."), @ApiResponse(code = 404, message = "The specified (storageId/repositoryId) does not exist!") }) @PreAuthorize("hasAuthority('MANAGEMENT_DELETE_TRASH')") @DeleteMapping(value = "{storageId}/{repositoryId}", produces = { MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity delete(@RepositoryMapping Repository repository,
                                 @RequestHeader(HttpHeaders.ACCEPT) String accept); @ApiOperation(value = "Used to delete the trash for all repositories.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The trash for all repositories was successfully removed."), @ApiResponse(code = 400, message = "Could not delete the trash for all repositories.") }) @PreAuthorize("hasAuthority('MANAGEMENT_DELETE_ALL_TRASHES')") @DeleteMapping(produces = { MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity delete(@RequestHeader(HttpHeaders.ACCEPT) String accept); @ApiOperation(value = "Used to undelete the trash for a path under a specified repository.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The trash for '${storageId}:${repositoryId}' was restored successfully."), @ApiResponse(code = 400, message = "Could not restore the trash for the specified repository."), @ApiResponse(code = 404, message = "The specified (storageId/repositoryId/path) does not exist!") }) @PreAuthorize("hasAuthority('MANAGEMENT_UNDELETE_TRASH')") @PostMapping("{storageId}/{repositoryId}/{path:.+}") ResponseEntity undelete(@RepositoryMapping Repository repository,
                                   @PathVariable String path,
                                   @RequestHeader(HttpHeaders.ACCEPT) String accept); @ApiOperation(value = "Used to undelete the trash for a specified repository.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The trash for '${storageId}:${repositoryId}' was restored successfully."), @ApiResponse(code = 400, message = "Could not restore the trash for a specified repository."), @ApiResponse(code = 404, message = "The specified (storageId/repositoryId) does not exist!") }) @PreAuthorize("hasAuthority('MANAGEMENT_UNDELETE_TRASH')") @PutMapping(value = "{storageId}/{repositoryId}", produces = { MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity undelete(@RepositoryMapping Repository repository,
                                   @RequestHeader(HttpHeaders.ACCEPT) String accept); @ApiOperation(value = "Used to undelete the trash for all repositories.") @ApiResponses(value = { @ApiResponse(code = 200, message = "The trash for all repositories was successfully restored."), @ApiResponse(code = 400, message = "Could not restore the trash for all repositories.") }) @PreAuthorize("hasAuthority('MANAGEMENT_UNDELETE_ALL_TRASHES')") @PostMapping(produces = { MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity undelete(@RequestHeader(HttpHeaders.ACCEPT) String accept);  }
@ExtendWith({ RepositoryManagementTestExecutionListener.class, ArtifactManagementTestExecutionListener.class }) @Test public void testForceDeleteArtifactNotAllowed(@MavenRepository(repositoryId = REPOSITORY_WITH_TRASH_1) @RepositoryAttributes(trashEnabled = true) Repository repository, @MavenTestArtifact(repositoryId = REPOSITORY_WITH_TRASH_1, id = "org.carlspring.strongbox:test-artifact-to-trash", versions = "1.0") Path artifactPath) throws IOException { final String storageId = repository.getStorage().getId(); final String repositoryId = repository.getId(); final RepositoryPath artifactRepositoryPath = (RepositoryPath) artifactPath.normalize(); final String artifactRepositoryPathStr = RepositoryFiles.relativizePath(artifactRepositoryPath); client.delete(storageId, repositoryId, artifactRepositoryPathStr, false); final Path artifactFile = RepositoryFiles.trash(artifactRepositoryPath); logger.debug("Artifact file: {}", artifactFile.toAbsolutePath()); assertThat(Files.exists(artifactFile)) .as("Should have moved the artifact to the trash during a force delete operation, " + "when allowsForceDeletion is not enabled!") .isTrue(); final RootRepositoryPath repositoryPath = repositoryPathResolver.resolve(repository); final Path repositoryIndexDir = repositoryPath.resolve(MavenRepositoryFeatures.INDEX); assertThat(Files.exists(repositoryIndexDir)).as("Should not have deleted .index directory!").isTrue(); }
@ExtendWith({ RepositoryManagementTestExecutionListener.class, ArtifactManagementTestExecutionListener.class }) @Test public void testForceDeleteArtifactAllowed(@MavenRepository(repositoryId = REPOSITORY_WITH_FORCE_DELETE_1) Repository repository, @MavenTestArtifact(repositoryId = REPOSITORY_WITH_FORCE_DELETE_1, id = "org.carlspring.strongbox:test-artifact-to-trash", versions = "1.1") Path artifactPath) throws IOException { final String storageId = repository.getStorage().getId(); final String repositoryId = repository.getId(); final RepositoryPath artifactRepositoryPath = (RepositoryPath) artifactPath.normalize(); final String artifactRepositoryPathStr = RepositoryFiles.relativizePath(artifactRepositoryPath); client.delete(storageId, repositoryId, artifactRepositoryPathStr, true); final Path artifactFileInTrash = RepositoryFiles.trash(artifactRepositoryPath); final RootRepositoryPath repositoryPath = repositoryPathResolver.resolve(repository); final Path repositoryDir = repositoryPath.resolve(repositoryId).resolve(".trash"); assertThat(Files.exists(artifactFileInTrash)) .as("Failed to delete artifact during a force delete operation!") .isFalse(); assertThat(Files.exists(repositoryDir.resolve(artifactRepositoryPathStr))) .as("Failed to delete artifact during a force delete operation!") .isFalse(); }