Skip to content

Commit

Permalink
EPMRPP-89699 || fixed filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Mar 18, 2024
1 parent 6ae1908 commit 08103da
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dependencies {
implementation 'com.epam.reportportal:plugin-api'
} else {
implementation 'com.github.reportportal:commons-events:e337f8b7be'
implementation 'com.github.reportportal:commons-dao:65eb641'
implementation 'com.github.reportportal:commons-dao:62b012d'
implementation 'com.github.reportportal:commons-rules:1f6bfed'
implementation 'com.github.reportportal:commons-model:38a52fb'
implementation 'com.github.reportportal:commons-reporting:5c74bb2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.LocalDateTime;
import java.util.Date;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class OrganizationInfoResource {

@NotNull
@JsonProperty(value = "creationDate", required = true)
private LocalDateTime creationDate;
private Date creationDate;

@JsonProperty(value = "usersQuantity", required = true)
private int usersQuantity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.epam.ta.reportportal.entity.enums.OrganizationType;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.LocalDateTime;
import java.util.Date;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -55,6 +55,6 @@ public class OrganizationResource {

@NotNull
@JsonProperty(value = "creationDate", required = true)
private LocalDateTime creationDate;
private Date creationDate;

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,16 @@ public Iterable<OrganizationInfoResource> getOrganizationsInfo(
pageable);
}

/**
* By security reasons "filter.*.user" should always be replaced with filter by current user.
* Only Admin users can retrieve all organizations regardless organization membership
*/
private void modifyFilterWithUserCriteria(Filter filter, ReportPortalUser user) {
// always remove user filter
filter.getFilterConditions()
.removeIf(cc -> cc.getAllConditions().stream()
.anyMatch(fc -> fc.getSearchCriteria().equalsIgnoreCase(USER)));

if (UserRole.ADMINISTRATOR != user.getUserRole()) {
filter.withCondition(
new FilterCondition(Condition.EQUALS, false, user.getUsername(), USER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.epam.ta.reportportal.ws.converter.converters;

import static com.epam.ta.reportportal.commons.EntityUtils.TO_DATE;

import com.epam.ta.reportportal.entity.organization.Organization;
import com.epam.ta.reportportal.entity.organization.OrganizationInfo;
import com.epam.ta.reportportal.model.organization.OrganizationInfoResource;
Expand All @@ -39,7 +41,7 @@ private OrganizationConverter() {
orgResource.setName(org.getName());
orgResource.setSlug(org.getSlug());
orgResource.setType(org.getOrganizationType());
orgResource.setCreationDate(org.getCreationDate());
orgResource.setCreationDate(TO_DATE.apply(org.getCreationDate()));

return orgResource;
};
Expand All @@ -50,7 +52,7 @@ private OrganizationConverter() {
orgInfoResource.setName(org.getName());
orgInfoResource.setSlug(org.getSlug());
orgInfoResource.setType(org.getOrganizationType());
orgInfoResource.setCreationDate(org.getCreationDate());
orgInfoResource.setCreationDate(TO_DATE.apply(org.getCreationDate()));
orgInfoResource.setLastRun(org.getLastRun());
orgInfoResource.setLaunchesQuantity(org.getLaunchesQuantity());
orgInfoResource.setProjectsQuantity(org.getProjectsQuantity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.epam.ta.reportportal.ws.converter.converters;

import com.epam.ta.reportportal.commons.MoreCollectors;
import com.epam.ta.reportportal.entity.organization.OrganizationUser;
import com.epam.ta.reportportal.entity.user.OrganizationUser;
import com.epam.ta.reportportal.entity.user.ProjectUser;
import com.epam.ta.reportportal.entity.user.User;
import com.epam.ta.reportportal.entity.user.UserType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,18 @@ void getAllOrganizationsInfo() throws Exception {
.with(token(oAuthHelper.getSuperadminToken())))
.andExpect(status().isOk());
}

@Test
void getAllOrganizationsInfoFilterByDifferentUser() throws Exception {
mockMvc.perform(get("/v1/organizations-info?filter.eq.user=default")
.with(token(oAuthHelper.getSuperadminToken())))
.andExpect(status().isOk());
}

@Test
void getAllOrganizationsInfoFilterByAdminUser() throws Exception {
mockMvc.perform(get("/v1/organizations-info?filter.eq.user=superadmin")
.with(token(oAuthHelper.getDefaultToken())))
.andExpect(status().isOk());
}
}
5 changes: 5 additions & 0 deletions src/test/resources/db/project/project-fill.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ values (3, 3, 'MEMBER');
insert into project_user(user_id, project_id, project_role)
values (1, 3, 'PROJECT_MANAGER');

insert into organization_user (user_id, organization_id, organization_role)
values (1, 101, (select 'MANAGER'::public."organization_role_enum"));
insert into organization_user (user_id, organization_id, organization_role)
values (3, 101, (select 'MEMBER'::public."organization_role_enum"));

insert into owned_entity(id, owner, project_id)
values (1, 'superadmin', 3);
insert into filter(id, name, target, description)
Expand Down

0 comments on commit 08103da

Please sign in to comment.