Skip to content

Commit

Permalink
EPMRPP-90309 || Empty content is returned for Admin user via API when…
Browse files Browse the repository at this point in the history
… searching for users
  • Loading branch information
APiankouski committed Apr 5, 2024
1 parent d328565 commit b78ea18
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.epam.ta.reportportal.commons.querygen.Queryable;
import com.epam.ta.reportportal.entity.jasper.ReportFormat;
import com.epam.ta.reportportal.entity.project.Project;
import com.epam.ta.reportportal.entity.user.UserRole;
import com.epam.ta.reportportal.ws.model.project.ProjectResource;
import com.epam.ta.reportportal.ws.model.user.SearchUserResource;
import com.epam.ta.reportportal.ws.model.user.UserResource;
Expand Down Expand Up @@ -87,7 +88,7 @@ public interface GetProjectHandler {
* @param pageable {@link Pageable} Page Details
* @return List of found user resources
*/
Iterable<SearchUserResource> getUserNames(String value,
Iterable<SearchUserResource> getUserNames(String value, UserRole userRole,
ReportPortalUser.ProjectDetails projectDetails, Pageable pageable);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.epam.ta.reportportal.entity.project.Project;
import com.epam.ta.reportportal.entity.project.ProjectInfo;
import com.epam.ta.reportportal.entity.user.User;
import com.epam.ta.reportportal.entity.user.UserRole;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.ws.converter.PagedResourcesAssembler;
import com.epam.ta.reportportal.ws.converter.converters.ProjectConverter;
Expand Down Expand Up @@ -151,11 +152,13 @@ private void checkBusinessRuleLessThan1Symbol(String value) {
}

@Override
public Iterable<SearchUserResource> getUserNames(String value, ReportPortalUser.ProjectDetails projectDetails, Pageable pageable) {
public Iterable<SearchUserResource> getUserNames(String value, UserRole userRole,
ReportPortalUser.ProjectDetails projectDetails, Pageable pageable) {
checkBusinessRuleLessThan1Symbol(value);

final CompositeFilterCondition userCondition =
isUserSuggestions ? getUserSearchSuggestCondition(value) : getUserSearchCondition(value);
(userRole.equals(UserRole.ADMINISTRATOR) || isUserSuggestions)
? getUserSearchSuggestCondition(value) : getUserSearchCondition(value);

final Filter filter = Filter.builder()
.withTarget(User.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public List<String> getProjectUsers(@PathVariable String projectName,
public Iterable<SearchUserResource> searchForUser(@PathVariable String projectName,
@RequestParam(value = "term") String term,
Pageable pageable, @AuthenticationPrincipal ReportPortalUser user) {
return getProjectHandler.getUserNames(term,
return getProjectHandler.getUserNames(term, user.getUserRole(),
projectExtractor.extractProjectDetails(user, projectName), pageable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void getUserNamesByIncorrectTerm() {

@Test
void getUserNamesNegative() {
ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.getUserNames("",
ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.getUserNames("", UserRole.ADMINISTRATOR,
new ReportPortalUser.ProjectDetails(1L, "superadmin_personal", ProjectRole.PROJECT_MANAGER),
PageRequest.of(0, 10)));
assertEquals("Incorrect filtering parameters. Length of the filtering string '' is less than 1 symbol", exception.getMessage());
Expand Down

0 comments on commit b78ea18

Please sign in to comment.