};
}
+ @DataProvider
+ public static List<Edition> editions_supporting_ai_code_assurance() {
+ return List.of(Edition.DEVELOPER, Edition.ENTERPRISE, Edition.DATACENTER);
+ }
+
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
assertThat(def.isPost()).isFalse();
assertThat(def.responseExampleAsString()).isNotEmpty();
assertThat(def.params().stream().map(Param::key).toList()).containsOnly("filter", "facets", "s", "asc", "ps", "p", "f");
- assertThat(def.changelog()).hasSize(4);
+ assertThat(def.changelog()).hasSize(5);
Param sort = def.param("s");
assertThat(sort.defaultValue()).isEqualTo("name");
tuple(publicProject.getKey(), publicProject.isPrivate() ? "private" : "public"));
}
+ @Test
+ public void ai_code_assured_is_always_false_for_community_edition() {
+ when(editionProviderMock.get()).thenReturn(Optional.of(Edition.COMMUNITY));
+ userSession.logIn();
+ ProjectDto aiAssuredProject = db.components().insertPublicProject(componentDto -> componentDto.setName("proj_A"),
+ projectDto -> projectDto.setAiCodeAssurance(true)).getProjectDto();
+ authorizationIndexerTester.allowOnlyAnyone(aiAssuredProject);
+ ProjectDto notAiAssuredProject = db.components().insertPrivateProject(componentDto -> componentDto.setName("proj_B"),
+ projectDto -> projectDto.setAiCodeAssurance(false)).getProjectDto();
+ authorizationIndexerTester.allowOnlyAnyone(notAiAssuredProject);
+ index();
+
+ SearchProjectsWsResponse result = call(request);
+
+ assertThat(result.getComponentsList()).extracting(Component::getKey, Component::getIsAiCodeAssured)
+ .containsExactly(
+ tuple(aiAssuredProject.getKey(), false),
+ tuple(notAiAssuredProject.getKey(), false));
+ }
+
+ @Test
+ @UseDataProvider("editions_supporting_ai_code_assurance")
+ public void return_ai_code_assured(Edition edition) {
+ when(editionProviderMock.get()).thenReturn(Optional.of(edition));
+ userSession.logIn();
+ ProjectDto aiAssuredProject = db.components().insertPublicProject(componentDto -> componentDto.setName("proj_A"),
+ projectDto -> projectDto.setAiCodeAssurance(true)).getProjectDto();
+ authorizationIndexerTester.allowOnlyAnyone(aiAssuredProject);
+ ProjectDto notAiAssuredProject = db.components().insertPrivateProject(componentDto -> componentDto.setName("proj_B"),
+ projectDto -> projectDto.setAiCodeAssurance(false)).getProjectDto();
+ authorizationIndexerTester.allowOnlyAnyone(notAiAssuredProject);
+ index();
+
+ SearchProjectsWsResponse result = call(request);
+
+ assertThat(result.getComponentsList()).extracting(Component::getKey, Component::getIsAiCodeAssured)
+ .containsExactly(
+ tuple(aiAssuredProject.getKey(), true),
+ tuple(notAiAssuredProject.getKey(), false));
+ }
+
@Test
public void does_not_return_branches() {
ProjectDto project = db.components().insertPublicProject().getProjectDto();
.addPagingParams(DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE)
.setInternal(true)
.setChangelog(
+ new Change("10.7", "Add 'isAiCodeAssured' response field"),
new Change("10.3", "Add 'creationDate' sort parameter."),
new Change("10.2", "Field 'needIssueSync' removed from response"),
new Change("8.3", "Add 'qualifier' filter and facet"),
}
private SearchProjectsWsResponse buildResponse(SearchProjectsRequest request, SearchResults searchResults) {
- Function<ProjectDto, Component> dbToWsComponent = new DbToWsComponent(request, searchResults, userSession.isLoggedIn());
+ Function<ProjectDto, Component> dbToWsComponent = new DbToWsComponent(request, searchResults, userSession.isLoggedIn(),
+ editionProvider.get().orElse(null));
return Stream.of(SearchProjectsWsResponse.newBuilder())
.map(response -> response.setPaging(Common.Paging.newBuilder()
private final boolean isUserLoggedIn;
private final Map<String, SnapshotDto> analysisByProjectUuid;
private final Map<String, Long> applicationsLeakPeriod;
+ private final Edition edition;
- private DbToWsComponent(SearchProjectsRequest request, SearchResults searchResults, boolean isUserLoggedIn) {
+ private DbToWsComponent(SearchProjectsRequest request, SearchResults searchResults, boolean isUserLoggedIn, @Nullable Edition edition) {
this.request = request;
this.analysisByProjectUuid = searchResults.analysisByProjectUuid;
this.applicationsLeakPeriod = searchResults.applicationsLeakPeriods;
this.wsComponent = Component.newBuilder();
this.favoriteProjectUuids = searchResults.favoriteProjectUuids;
this.isUserLoggedIn = isUserLoggedIn;
+ this.edition = edition;
}
@Override
.setKey(dbProject.getKey())
.setName(dbProject.getName())
.setQualifier(dbProject.getQualifier())
- .setVisibility(Visibility.getLabel(dbProject.isPrivate()));
+ .setVisibility(Visibility.getLabel(dbProject.isPrivate()))
+ .setIsAiCodeAssured(isAiCodeAssured(dbProject));
wsComponent.getTagsBuilder().addAllTags(dbProject.getTags());
SnapshotDto snapshotDto = analysisByProjectUuid.get(dbProject.getUuid());
return wsComponent.build();
}
+
+ /**
+ * Make sure that for {@link Edition#COMMUNITY} we'll always get false, no matter of the value in database.
+ * This is to support correctly downgraded instances.
+ */
+ private boolean isAiCodeAssured(ProjectDto dbProject) {
+ return edition != null && !edition.equals(Edition.COMMUNITY) && dbProject.getAiCodeAssurance();
+ }
}
public static class SearchResults {
private final ProjectMeasuresQuery query;
private final int total;
- private SearchResults(List<ProjectDto> projects, Set<String> favoriteProjectUuids, SearchIdResult<String> searchResults, Map<String, SnapshotDto> analysisByProjectUuid,
+ private SearchResults(List<ProjectDto> projects, Set<String> favoriteProjectUuids, SearchIdResult<String> searchResults, Map<String,
+ SnapshotDto> analysisByProjectUuid,
Map<String, Long> applicationsLeakPeriods, ProjectMeasuresQuery query) {
this.projects = projects;
this.favoriteProjectUuids = favoriteProjectUuids;