Skip to content
Snippets Groups Projects
Commit 404616ea authored by kbeyro's avatar kbeyro
Browse files

Bulk delete update

parent 96791eb7
Branches
Tags
3 merge requests!65Resolve "Prevent users from adding an existing SSH key",!601.6.5 fix processing bulk,!1119 add endpoint for bulk deployment removal
Pipeline #89082 passed
...@@ -14,6 +14,7 @@ import net.geant.nmaas.portal.service.BulkDomainService; ...@@ -14,6 +14,7 @@ import net.geant.nmaas.portal.service.BulkDomainService;
import net.geant.nmaas.portal.service.UserService; import net.geant.nmaas.portal.service.UserService;
import org.modelmapper.ModelMapper; import org.modelmapper.ModelMapper;
import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.InputStreamResource;
import org.springframework.dao.PermissionDeniedDataAccessException;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
...@@ -151,16 +152,22 @@ public class BulkController { ...@@ -151,16 +152,22 @@ public class BulkController {
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN')") @PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_VL_MANAGER')")
public ResponseEntity<Void> removeBulkDeployment( public ResponseEntity<Void> removeBulkDeployment(
@PathVariable Long id, @PathVariable Long id,
@RequestParam(name = "removeAll") boolean removeApps @RequestParam(name = "removeAll") boolean removeApps,
Principal principal
) { ) {
User user = this.userService.findByUsername(principal.getName()).orElseThrow(() -> new MissingElementException("Missing user " + principal.getName()));
Optional<BulkDeployment> bulk = this.bulkDeploymentRepository.findById(id); Optional<BulkDeployment> bulk = this.bulkDeploymentRepository.findById(id);
if (bulk.isEmpty()) { if (bulk.isEmpty()) {
return ResponseEntity.notFound().build(); return ResponseEntity.notFound().build();
} }
if(bulk.get().getCreatorId().equals(user.getId()) ) {
throw new PermissionDeniedDataAccessException("User doesnt have access to this bulk deployment", new Throwable());
}
if (removeApps) { if (removeApps) {
bulkApplicationService.deleteAppInstancesFromBulk(mapToView(bulk.get(), BulkDeploymentView.class)); bulkApplicationService.deleteAppInstancesFromBulk(mapToView(bulk.get(), BulkDeploymentView.class));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment