]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15567 Add new `projectImportFeatureEnabled` feature flag (#4891)
authorklaudio-sinani-sonarsource <92299827+klaudio-sinani-sonarsource@users.noreply.github.com>
Tue, 26 Oct 2021 14:36:50 +0000 (16:36 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 4 Nov 2021 20:03:24 +0000 (20:03 +0000)
* SONAR-15567 Introduce new `projectImportFeatureEnabled` feature flag

* SONAR-15567 Add test cases for new `projectImportFeatureEnabled` feature flag

* SONAR-15567 Update API example payload for `api/navigation/global`

* SONAR-15567 Minor fix on order of imports

* SONAR-15567 Remove new line characters

server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java

index 28ed4f358985cd93687bf86c640d4d1bcd9d7d83..32ff442e996c7bd072cad278d3795dedc0cce78f 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.ui.ws;
 
 import com.google.common.collect.ImmutableSet;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -34,6 +35,7 @@ import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService.NewController;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.api.web.page.Page;
+import org.sonar.core.platform.EditionProvider;
 import org.sonar.core.platform.PlatformEditionProvider;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
@@ -54,6 +56,8 @@ import static org.sonar.core.config.WebConstants.SONAR_LF_ENABLE_GRAVATAR;
 import static org.sonar.core.config.WebConstants.SONAR_LF_GRAVATAR_SERVER_URL;
 import static org.sonar.core.config.WebConstants.SONAR_LF_LOGO_URL;
 import static org.sonar.core.config.WebConstants.SONAR_LF_LOGO_WIDTH_PX;
+import static org.sonar.core.platform.EditionProvider.Edition.DATACENTER;
+import static org.sonar.core.platform.EditionProvider.Edition.ENTERPRISE;
 import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_ENABLED;
 import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_HOMEPAGE_URL;
 import static org.sonar.process.ProcessProperties.Property.SONAR_ANALYTICS_GTM_TRACKING_ID;
@@ -146,6 +150,7 @@ public class GlobalAction implements NavigationWsAction, Startable {
       writeBranchSupport(json);
       writeInstanceUsesDefaultAdminCredentials(json);
       writeMultipleAlmEnabled(json);
+      writeProjectImportFeature(json);
       editionProvider.get().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH)));
       writeNeedIssueSync(json);
       json.prop("standalone", webServer.isStandalone());
@@ -212,6 +217,12 @@ public class GlobalAction implements NavigationWsAction, Startable {
     json.prop("multipleAlmEnabled", multipleAlmFeatureProvider.enabled());
   }
 
+  private void writeProjectImportFeature(JsonWriter json) {
+    EditionProvider.Edition edition = editionProvider.get().orElse(null);
+    boolean isEnabled = Arrays.asList(ENTERPRISE, DATACENTER).contains(edition);
+    json.prop("projectImportFeatureEnabled", isEnabled);
+  }
+
   private void writeNeedIssueSync(JsonWriter json) {
     try (DbSession dbSession = dbClient.openSession(false)) {
       json.prop("needIssueSync", issueIndexSyncChecker.isIssueSyncInProgress(dbSession));
index 700eee264bc63ef24358c7b8dffecdfb11092abf..7a110f13d789b17f4bfd269264a066dd831001cb 100644 (file)
@@ -26,6 +26,7 @@
   "version": "6.2",
   "productionDatabase": true,
   "branchesEnabled": false,
+  "projectImportFeatureEnabled": false,
   "canAdmin": false,
   "standalone": true,
   "edition": "community"
index 7acb72b8df397ff1b70fb6736ee4a353594890e5..6f350accf9fb43a725ae0b89b1fc9177dcecd734 100644 (file)
@@ -48,10 +48,12 @@ import org.sonar.server.ws.WsActionTester;
 import org.sonar.updatecenter.common.Version;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.InstanceOfAssertFactories.optional;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.core.platform.EditionProvider.Edition.*;
 import static org.sonar.test.JsonAssert.assertJson;
 
 public class GlobalActionTest {
@@ -254,6 +256,29 @@ public class GlobalActionTest {
 
   }
 
+  @Test
+  public void project_import_feature_enabled_ee_dce() {
+    init();
+    when(editionProvider.get()).thenReturn(Optional.of(ENTERPRISE));
+    assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":true}");
+
+    when(editionProvider.get()).thenReturn(Optional.of(DATACENTER));
+    assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":true}");
+  }
+
+  @Test
+  public void project_import_feature_disabled_ce_de() {
+    init();
+    when(editionProvider.get()).thenReturn(Optional.of(COMMUNITY));
+    assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}");
+
+    when(editionProvider.get()).thenReturn(Optional.of(DEVELOPER));
+    assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}");
+
+    when(editionProvider.get()).thenReturn(Optional.empty());
+    assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}");
+  }
+
   @Test
   public void return_need_issue_sync() {
     init();