diff --git a/packages/code-server/code-server-lib/src/main/java/com/daimler/data/controller/WorkspaceController.java b/packages/code-server/code-server-lib/src/main/java/com/daimler/data/controller/WorkspaceController.java index c923444c30..266a81695d 100644 --- a/packages/code-server/code-server-lib/src/main/java/com/daimler/data/controller/WorkspaceController.java +++ b/packages/code-server/code-server-lib/src/main/java/com/daimler/data/controller/WorkspaceController.java @@ -966,7 +966,7 @@ public ResponseEntity deleteWorkspace( return new ResponseEntity<>(emptyResponse, HttpStatus.NOT_FOUND); } if (!(vo != null && vo.getWorkspaceOwner() != null - && vo.getWorkspaceOwner().getId().equalsIgnoreCase(userId))) { + && vo.getWorkspaceOwner().getId().equalsIgnoreCase(userId)||userStore.getUserInfo().hasSuperAdminAccess())) { MessageDescription notAuthorizedMsg = new MessageDescription(); notAuthorizedMsg.setMessage( "Not authorized to delete workspace. User does not have privileges."); @@ -994,6 +994,7 @@ public ResponseEntity deleteWorkspace( log.info("Cannot delete workspace {} as its not created yet. Bad Request", vo.getWorkspaceId()); return new ResponseEntity<>(errorMessage, HttpStatus.BAD_REQUEST); } + if(!userStore.getUserInfo().hasSuperAdminAccess()){ if (vo != null && vo.getProjectDetails().getProjectOwner() != null && vo.getProjectDetails().getProjectOwner().getId().equalsIgnoreCase(userId) && vo.getProjectDetails().getProjectCollaborators() != null @@ -1007,6 +1008,7 @@ public ResponseEntity deleteWorkspace( "You have collaborators in your project. Please transfer your ownership to any one of the collaborator before deleting this project codespace"); return new ResponseEntity<>(errorMessage, HttpStatus.BAD_REQUEST); } + } GenericMessage responseMsg = service.deleteById(userId, id); log.info("User {} deleted workspace {}", userId, vo.getWorkspaceId()); return new ResponseEntity<>(responseMsg, HttpStatus.OK); diff --git a/packages/code-server/code-server-lib/src/main/java/com/daimler/data/service/workspace/BaseWorkspaceService.java b/packages/code-server/code-server-lib/src/main/java/com/daimler/data/service/workspace/BaseWorkspaceService.java index ffcd736be5..ec90badb83 100644 --- a/packages/code-server/code-server-lib/src/main/java/com/daimler/data/service/workspace/BaseWorkspaceService.java +++ b/packages/code-server/code-server-lib/src/main/java/com/daimler/data/service/workspace/BaseWorkspaceService.java @@ -188,14 +188,22 @@ public GenericMessage deleteById(String userId, String id) { GenericMessage responseMessage = new GenericMessage(); List errors = new ArrayList<>(); List warnings = new ArrayList<>(); - CodeServerWorkspaceNsql entity = workspaceCustomRepository.findById(userId, id); + CodeServerWorkspaceNsql entity = new CodeServerWorkspaceNsql(); + + if(userStore.getUserInfo().hasSuperAdminAccess()){ + entity = workspaceCustomRepository.findByWorkspaceId(id); + } + else{ + entity = workspaceCustomRepository.findById(userId, id); + } String cloudServiceProvider = entity.getData().getProjectDetails().getRecipeDetails().getCloudServiceProvider(); boolean isProjectOwner = false; boolean isCodespaceDeployed = false; String projectOwnerId = entity.getData().getProjectDetails().getProjectOwner().getId(); - if (projectOwnerId.equalsIgnoreCase(userId)) { + if (projectOwnerId.equalsIgnoreCase(userId) ||userStore.getUserInfo().hasSuperAdminAccess()) { isProjectOwner = true; } + if (isProjectOwner) { log.info("Delete requested by project owner {} ", userId); diff --git a/packages/code-server/code-server-lib/src/main/resources/application.yml b/packages/code-server/code-server-lib/src/main/resources/application.yml index 95e2dc60f2..3a83d56242 100644 --- a/packages/code-server/code-server-lib/src/main/resources/application.yml +++ b/packages/code-server/code-server-lib/src/main/resources/application.yml @@ -2,7 +2,7 @@ spring: mvc.pathmatch.matching-strategy: ant_path_matcher application: name: dna-codeserver-service - version: 1.3.9 + version: 1.3.10 profile: active: production