Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMRPP-97062 delete avatar #2145

Open
wants to merge 1 commit into
base: feature/orgs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public interface EditUserHandler {
*/
OperationCompletionRS deletePhoto(String username);

/**
* Delete user's photo.
*
* @param userId id of user
*/
void deletePhoto(Long userId);

/**
* Change password
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ public OperationCompletionRS deletePhoto(String login) {
return new OperationCompletionRS("Profile photo has been deleted successfully");
}

@Override
public void deletePhoto(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new ReportPortalException(ErrorType.USER_NOT_FOUND, userId));
expect(user.getUserType(), equalTo(INTERNAL)).verify(ACCESS_DENIED,
"Unable to change photo for external user");
userBinaryDataService.deleteUserPhoto(user);
}

@Override
public OperationCompletionRS changePassword(ReportPortalUser loggedInUser,
ChangePasswordRQ request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void getUserPhoto(@PathVariable String projectKey,
@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);
Expand All @@ -119,6 +120,7 @@ public OperationCompletionRS uploadPhoto(@RequestParam("file") MultipartFile fil
@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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,12 @@ public ResponseEntity<Void> postUsersUserIdAvatar(Long userId,
editUserHandler.uploadPhoto(userId, file);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@Override
@Transactional
@PreAuthorize(ALLOWED_TO_USER_ITSELF)
public ResponseEntity<Void> deleteUsersUserIdAvatar(Long userId) {
editUserHandler.deletePhoto(userId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ void userPhoto() throws Exception {
token(oAuthHelper.getDefaultToken())))
.andExpect(status().isOk());

mockMvc.perform(delete("/v1/data/photo").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")
public void testUserPhotoAccessDeniedForCustomer() throws Exception {
void testUserPhotoAccessDeniedForCustomer() throws Exception {
mockMvc.perform(get("/v1/data/default_personal/userphoto?login=default").with(
token(oAuthHelper.getCustomerToken())))
.andExpect(status().isForbidden());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void userPhoto() throws Exception {
token(oAuthHelper.getDefaultToken())))
.andExpect(status().isOk());

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