]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16316 Add new `regulatoryReportFeatureEnabled` feature flag
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>
Thu, 5 May 2022 13:46:31 +0000 (15:46 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 25 May 2022 20:03:16 +0000 (20:03 +0000)
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 456c2500b05135e6fa04b0be48ba920edcb28aed..a5b145d8d4141c7e5b1311ad762b5f2555158ae6 100644 (file)
@@ -25,6 +25,7 @@ import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import javax.annotation.Nullable;
 import org.sonar.api.Startable;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.platform.Server;
@@ -35,7 +36,6 @@ 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;
@@ -56,6 +56,7 @@ 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;
 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;
@@ -74,6 +75,8 @@ public class GlobalAction implements NavigationWsAction, Startable {
     RATING_GRID,
     DEVELOPER_AGGREGATED_INFO_DISABLED);
 
+  private static final String REGULATORY_REPORT_FEATURE_ENABLED_FLAG  = "regulatoryReportFeatureEnabled";
+  
   private final Map<String, String> systemSettingValuesByKey;
 
   private final PageRepository pageRepository;
@@ -151,6 +154,7 @@ public class GlobalAction implements NavigationWsAction, Startable {
       writeInstanceUsesDefaultAdminCredentials(json);
       writeMultipleAlmEnabled(json);
       writeProjectImportFeature(json);
+      writeRegulatoryReportFeature(json);
       editionProvider.get().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH)));
       writeNeedIssueSync(json);
       json.prop("standalone", webServer.isStandalone());
@@ -218,8 +222,8 @@ public class GlobalAction implements NavigationWsAction, Startable {
   }
 
   private void writeProjectImportFeature(JsonWriter json) {
-    EditionProvider.Edition edition = editionProvider.get().orElse(null);
-    boolean isEnabled = Arrays.asList(ENTERPRISE, DATACENTER).contains(edition);
+    Edition edition = editionProvider.get().orElse(null);
+    boolean isEnabled = isEditionEEorDCE(edition);
     json.prop("projectImportFeatureEnabled", isEnabled);
   }
 
@@ -232,4 +236,14 @@ public class GlobalAction implements NavigationWsAction, Startable {
   private void writeWebAnalytics(JsonWriter json) {
     webAnalyticsLoader.getUrlPathToJs().ifPresent(p -> json.prop("webAnalyticsJsPath", p));
   }
+
+  private void writeRegulatoryReportFeature(JsonWriter json) {
+    Edition edition = editionProvider.get().orElse(null);
+    boolean isEnabled = isEditionEEorDCE(edition);
+    json.prop(REGULATORY_REPORT_FEATURE_ENABLED_FLAG, isEnabled);
+  }
+
+  private static boolean isEditionEEorDCE(@Nullable Edition edition) {
+    return Arrays.asList(ENTERPRISE, DATACENTER).contains(edition);
+  }
 }
index 7a110f13d789b17f4bfd269264a066dd831001cb..a9779b55d4138950aceb0026c1dcf408220e593a 100644 (file)
@@ -27,6 +27,7 @@
   "productionDatabase": true,
   "branchesEnabled": false,
   "projectImportFeatureEnabled": false,
+  "regulatoryReportFeatureEnabled": false,
   "canAdmin": false,
   "standalone": true,
   "edition": "community"
index 135663c706c9148289be797ac0ef014096839934..cd3263e4f5bfbaf28501f3fd780cf1b7e7015958 100644 (file)
@@ -278,6 +278,7 @@ public class GlobalActionTest {
     assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}");
   }
 
+
   @Test
   public void return_need_issue_sync() {
     init();
@@ -296,6 +297,29 @@ public class GlobalActionTest {
     assertJson(call()).isSimilarTo("{\"canAdmin\":true}");
   }
 
+  @Test
+  public void regulatory_report_feature_enabled_ee_dce() {
+    init();
+    when(editionProvider.get()).thenReturn(Optional.of(ENTERPRISE));
+    assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":true}");
+
+    when(editionProvider.get()).thenReturn(Optional.of(DATACENTER));
+    assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":true}");
+  }
+
+  @Test
+  public void regulatory_report_feature_disabled_ce_de() {
+    init();
+    when(editionProvider.get()).thenReturn(Optional.of(COMMUNITY));
+    assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":false}");
+
+    when(editionProvider.get()).thenReturn(Optional.of(DEVELOPER));
+    assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":false}");
+
+    when(editionProvider.get()).thenReturn(Optional.empty());
+    assertJson(call()).isSimilarTo("{\"regulatoryReportFeatureEnabled\":false}");
+  }
+
   @Test
   public void instance_uses_default_admin_credentials() {
     init();