private List<ProjectQgateAssociationDto> keepAuthorizedProjects(DbSession dbSession, List<ProjectQgateAssociationDto> projects) { if (userSession.isRoot()) { // the method AuthorizationDao#keepAuthorizedProjectIds() should be replaced by // a call to UserSession, which would transparently support roots. // Meanwhile root is explicitly handled. return projects; } List<Long> projectIds = projects.stream().map(ProjectQgateAssociationDto::getId).collect(MoreCollectors.toList()); Collection<Long> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedProjectIds(dbSession, projectIds, userSession.getUserId(), UserRole.USER); return projects.stream().filter(project -> authorizedProjectIds.contains(project.getId())).collect(MoreCollectors.toList()); }
@Test public void to_assoc_with_project_not_having_assoc() { ProjectQgateAssociation project = new ProjectQgateAssociationDto() .setId(1L) .setName("polop") .setGateId(null) .toQgateAssociation(); assertThat(project.id()).isEqualTo(1); assertThat(project.name()).isEqualTo("polop"); assertThat(project.isMember()).isFalse(); }
@Test public void to_assoc_with_project_having_assoc() { ProjectQgateAssociation project = new ProjectQgateAssociationDto() .setId(1L) .setName("polop") .setGateId("10") .toQgateAssociation(); assertThat(project.id()).isEqualTo(1); assertThat(project.name()).isEqualTo("polop"); assertThat(project.isMember()).isTrue(); }
private List<ProjectQgateAssociationDto> keepAuthorizedProjects(DbSession dbSession, List<ProjectQgateAssociationDto> projects) { if (userSession.isRoot()) { // the method AuthorizationDao#keepAuthorizedProjectIds() should be replaced by // a call to UserSession, which would transparently support roots. // Meanwhile root is explicitly handled. return projects; } List<Long> projectIds = projects.stream().map(ProjectQgateAssociationDto::getId).collect(MoreCollectors.toList()); Collection<Long> authorizedProjectIds = dbClient.authorizationDao().keepAuthorizedProjectIds(dbSession, projectIds, userSession.getUserId(), UserRole.USER); return projects.stream().filter(project -> authorizedProjectIds.contains(project.getId())).collect(MoreCollectors.toList()); }