Skip to content

Commit

Permalink
EPMRPP-97478 delete deprecated endpoints (#2147)
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx authored Jan 20, 2025
1 parent f24ac45 commit 86c50e9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
import static com.epam.ta.reportportal.auth.permissions.Permissions.ALLOWED_TO_VIEW_PROJECT;
import static com.epam.ta.reportportal.auth.permissions.Permissions.IS_ADMIN;

import com.epam.ta.reportportal.commons.EntityUtils;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.core.file.DeleteFilesHandler;
import com.epam.ta.reportportal.core.file.GetFileHandler;
import com.epam.ta.reportportal.core.user.EditUserHandler;
import com.epam.ta.reportportal.entity.attachment.BinaryData;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.util.ProjectExtractor;
import com.epam.ta.reportportal.ws.reporting.OperationCompletionRS;
import com.google.common.net.HttpHeaders;
Expand All @@ -41,7 +40,6 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -83,47 +81,6 @@ public void getFile(@PathVariable String projectKey, @PathVariable("dataId") Lon
projectExtractor.extractMembershipDetails(user, projectKey)));
}

@Transactional(readOnly = true)
@GetMapping(value = "/photo")
@Operation(summary = "Get photo of current user")
@Deprecated(forRemoval = true)
public void getMyPhoto(@AuthenticationPrincipal ReportPortalUser user,
HttpServletResponse response,
@RequestParam(value = "loadThumbnail", required = false) boolean loadThumbnail) {
toResponse(response, getFileHandler.getUserPhoto(user, loadThumbnail));
}

@Transactional(readOnly = true)
@GetMapping(value = "/{projectKey}/userphoto")
@Operation(summary = "Get user's photo")
@PreAuthorize(ALLOWED_TO_VIEW_PROJECT)
@Deprecated(forRemoval = true)
public void getUserPhoto(@PathVariable String projectKey,
@RequestParam(value = "login") String username,
@RequestParam(value = "loadThumbnail", required = false) boolean loadThumbnail,
HttpServletResponse response,
@AuthenticationPrincipal ReportPortalUser user) {
BinaryData userPhoto = getFileHandler.getUserPhoto(EntityUtils.normalizeId(username), user,
projectKey, loadThumbnail);
toResponse(response, userPhoto);
}

@Transactional
@PostMapping(value = "/photo", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
@Operation(summary = "Upload user's photo")
@Deprecated(forRemoval = true)
public OperationCompletionRS uploadPhoto(@RequestParam("file") MultipartFile file,
@AuthenticationPrincipal ReportPortalUser user) {
return editUserHandler.uploadPhoto(EntityUtils.normalizeId(user.getUsername()), file);
}

@Transactional
@DeleteMapping(value = "/photo")
@Operation(summary = "Delete user's photo")
@Deprecated(forRemoval = true)
public OperationCompletionRS deletePhoto(@AuthenticationPrincipal ReportPortalUser user) {
return editUserHandler.deletePhoto(EntityUtils.normalizeId(user.getUsername()));
}

@Transactional
@PreAuthorize(IS_ADMIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,10 @@ void userPhoto() throws Exception {
mockMvc.perform(get("/users/2/avatar").with(token(oAuthHelper.getDefaultToken())))
.andExpect(status().isOk());

mockMvc.perform(get("/v1/data/default_personal/userphoto?login=default").with(
token(oAuthHelper.getDefaultToken())))
.andExpect(status().isOk());

mockMvc.perform(delete("/users/2/avatar").with(token(oAuthHelper.getDefaultToken())))
.andExpect(status().isNoContent());
}

@Test
@Sql("/db/user/user-viewer.sql")
void testUserPhotoAccessDeniedForCustomer() throws Exception {
mockMvc.perform(get("/v1/data/default_personal/userphoto?login=default").with(
token(oAuthHelper.getCustomerToken())))
.andExpect(status().isForbidden());
}

@Test
void uploadLargeUserPhoto() throws Exception {
final MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.multipart(
Expand Down Expand Up @@ -157,23 +145,11 @@ void getFile() throws Exception {
.andExpect(status().isOk());
}

@Test
void getUserPhotoNegative() throws Exception {
mockMvc.perform(get("/v1/data/photo").with(token(oAuthHelper.getDefaultToken())))
.andExpect(status().isOk());
}

@Test
void getUserPhotoByLoginNegative() throws Exception {
mockMvc.perform(get("/v1/data/superadmin_personal/userphoto?login=superadmin").with(
token(oAuthHelper.getSuperadminToken())))
.andExpect(status().isOk());
}

@Test
void getNotExistUserPhoto() throws Exception {
mockMvc.perform(
get("/v1/data/userphoto?login=not_exist")
get("/users/999/avatar")
.with(token(oAuthHelper.getSuperadminToken())))
.andExpect(status().isNotFound());
}
Expand Down

0 comments on commit 86c50e9

Please sign in to comment.