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-97027 user avatar #2111

Merged
merged 4 commits into from
Dec 3, 2024
Merged
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
@@ -0,0 +1,14 @@
package com.epam.ta.reportportal.auth.permissions;

import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

@Component("authenticatedUserPermission")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck> reported by reviewdog 🐶
Missing a Javadoc comment.

@LookupPermission({"authenticated"})
public class Authenticated implements Permission {

@Override
public boolean isAllowed(Authentication authentication, Object invitationRequest) {
return authentication.isAuthenticated();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ private Permissions() {
public static final String ALLOWED_TO_VIEW_PROJECT =
"hasPermission(#projectKey.toLowerCase(), 'allowedToViewProject')" + "||" + IS_ADMIN;

public static final String AUTHENTICATED = IS_ADMIN + "||" + "hasPermission(#userId, 'authenticated')";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 100 characters (found 105).


public static final String INVITATION_ALLOWED = IS_ADMIN + "||"
+ "hasPermission(#invitationRequest, 'invitationAllowed')";
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.springframework.http.MediaType;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.ResourceHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.validation.beanvalidation.BeanValidationPostProcessor;
Expand Down Expand Up @@ -121,6 +122,7 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentRes
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.clear();
converters.add(resourceConverter());
converters.add(byteArrayConverter());
converters.add(jsonConverter());
converters.add(openMetricsTextStringConverter());
Expand Down Expand Up @@ -173,6 +175,11 @@ public StringHttpMessageConverter stringConverter() {
return converter;
}

@Bean
public ResourceHttpMessageConverter resourceConverter() {
return new ResourceHttpMessageConverter();
}

@Bean
public StringHttpMessageConverter openMetricsTextStringConverter() {
StringHttpMessageConverter converter = new StringHttpMessageConverter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public interface GetFileHandler {
*/
BinaryData getUserPhoto(ReportPortalUser loggedInUser, boolean loadThumbnail);

/**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [reviewdog] <com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck> reported by reviewdog 🐶
First sentence of Javadoc is missing an ending period.

* Returns {@link InputStream} for current logged-in user photo.
*
* @param userId requested user Id {@link Long}
* @param loadThumbnail true if needed to load thumbnail
* @return {@link BinaryData}
*/
BinaryData getUserPhoto(Long userId, boolean loadThumbnail);

/**
* Returns {@link InputStream} for photo of the {@link com.epam.ta.reportportal.entity.user.User}
* with specified username
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public BinaryData getUserPhoto(ReportPortalUser loggedInUser, boolean loadThumbn
return userDataStoreService.loadUserPhoto(user, loadThumbnail);
}

@Override
public BinaryData getUserPhoto(Long userId, boolean loadThumbnail) {
var user = userRepository.findById(userId)
.orElseThrow(() -> new ReportPortalException(ErrorType.USER_NOT_FOUND, userId));

return userDataStoreService.loadUserPhoto(user, loadThumbnail);
}


@Override
public BinaryData getUserPhoto(String username, ReportPortalUser loggedInUser, String projectKey,
boolean loadThumbnail) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void getFile(@PathVariable String projectKey, @PathVariable("dataId") Lon
@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) {
Expand All @@ -96,6 +97,7 @@ public void getMyPhoto(@AuthenticationPrincipal ReportPortalUser user,
@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,
Expand Down
Loading