]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20393 allow to deactivate GH project visibility sync
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Mon, 11 Sep 2023 13:35:22 +0000 (15:35 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 12 Sep 2023 20:02:41 +0000 (20:02 +0000)
server/sonar-auth-github/src/main/java/org/sonar/auth/github/GitHubSettings.java
server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubModuleTest.java
server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubSettingsTest.java
server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts

index 620d7652df3a572519838570be08734740c30d78..bd93b13cfbba7ac8b552fc53b0af8e08e63080b7 100644 (file)
@@ -61,12 +61,13 @@ public class GitHubSettings {
   @VisibleForTesting
   static final String PROVISIONING = "provisioning.github.enabled";
   @VisibleForTesting
+  static final String PROVISION_VISIBILITY = "provisioning.github.project.visibility.enabled";
+  @VisibleForTesting
   static final String USER_CONSENT_FOR_PERMISSIONS_REQUIRED_AFTER_UPGRADE = "sonar.auth.github.userConsentForPermissionProvisioningRequired";
 
   private static final String CATEGORY = "authentication";
   private static final String SUBCATEGORY = "github";
 
-
   private final Configuration configuration;
 
   private final InternalProperties internalProperties;
@@ -166,6 +167,10 @@ public class GitHubSettings {
     return configuration.get(USER_CONSENT_FOR_PERMISSIONS_REQUIRED_AFTER_UPGRADE).isPresent();
   }
 
+  public boolean isProjectVisibilitySynchronizationActivated() {
+    return configuration.getBoolean(PROVISION_VISIBILITY).orElse(true);
+  }
+
   public static List<PropertyDefinition> definitions() {
     int index = 1;
     return Arrays.asList(
@@ -255,6 +260,16 @@ public class GitHubSettings {
         .category(CATEGORY)
         .subCategory(SUBCATEGORY)
         .index(index)
+        .build(),
+      PropertyDefinition.builder(PROVISION_VISIBILITY)
+        .name("Provision project visibility")
+        .description("Change project visibility based on GitHub repository visibility. If disabled, every provisioned project will be private and will be seen only for those users"
+                     + " that have explicit GitHub permissions for the according repository.")
+        .type(BOOLEAN)
+        .category(CATEGORY)
+        .subCategory(SUBCATEGORY)
+        .defaultValue(valueOf(true))
+        .index(index)
         .build());
   }
 }
index ebb9b1b1f2beb8b66ddf76ffcc1549467c4368c8..635dbf1df54178edd0fffcdaab7fba574a37f174 100644 (file)
@@ -30,7 +30,7 @@ public class GitHubModuleTest {
   public void verify_count_of_added_components() {
     ListContainer container = new ListContainer();
     new GitHubModule().configure(container);
-    assertThat(container.getAddedObjects()).hasSize(14);
+    assertThat(container.getAddedObjects()).hasSize(15);
   }
 
 }
index fa31f09f9ce54d94ff0dec1aea6dd14f367ea761..5641897330fe372ca14703792e3d8642584501e8 100644 (file)
@@ -37,15 +37,16 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.sonar.auth.github.GitHubSettings.USER_CONSENT_FOR_PERMISSIONS_REQUIRED_AFTER_UPGRADE;
+import static org.sonar.auth.github.GitHubSettings.PROVISION_VISIBILITY;
 
 public class GitHubSettingsTest {
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
 
-  private MapSettings settings = new MapSettings(new PropertyDefinitions(System2.INSTANCE, GitHubSettings.definitions()));
-  private InternalProperties internalProperties = mock(InternalProperties.class);
+  private final MapSettings settings = new MapSettings(new PropertyDefinitions(System2.INSTANCE, GitHubSettings.definitions()));
+  private final InternalProperties internalProperties = mock(InternalProperties.class);
 
-  private GitHubSettings underTest = new GitHubSettings(settings.asConfig(), internalProperties, db.getDbClient());
+  private final GitHubSettings underTest = new GitHubSettings(settings.asConfig(), internalProperties, db.getDbClient());
 
   @Test
   public void is_enabled() {
@@ -113,6 +114,22 @@ public class GitHubSettingsTest {
     assertThat(underTest.isUserConsentRequiredAfterUpgrade()).isTrue();
   }
 
+  @Test
+  public void isProjectVisibilitySynchronizationActivated_whenPropertyNotSet_returnsTrueByDefault() {
+    assertThat(underTest.isProjectVisibilitySynchronizationActivated()).isTrue();
+  }
+
+  @Test
+  public void isProjectVisibilitySynchronizationActivated_whenPropertyIsSetToFalse_returnsFalse() {
+    settings.setProperty(PROVISION_VISIBILITY, "false");
+    assertThat(underTest.isProjectVisibilitySynchronizationActivated()).isFalse();
+  }
+  @Test
+  public void isProjectVisibilitySynchronizationActivated_whenPropertyIsSetToTrue_returnsTrue() {
+    settings.setProperty(PROVISION_VISIBILITY, "true");
+    assertThat(underTest.isProjectVisibilitySynchronizationActivated()).isTrue();
+  }
+
   @Test
   public void setProvisioning_whenGitHubAuthDisabled_shouldThrow() {
     assertThatIllegalStateException()
@@ -273,7 +290,8 @@ public class GitHubSettingsTest {
         "Synchronize teams as groups",
         "The API url for a GitHub instance.",
         "The WEB url for a GitHub instance.",
-        "Organizations");
+        "Organizations",
+        "Provision project visibility");
   }
 
   private void enableGithubAuthentication() {
index 5ad6944dd0d29397f4528080b953771c1a697c24..6f9ac390726924d373564e03b3eb74e760d3c153 100644 (file)
@@ -39,6 +39,7 @@ export const OPTIONAL_FIELDS = [
   ...GITHUB_JIT_FIELDS,
   'sonar.auth.github.organizations',
   'sonar.auth.github.groupsSync',
+  'provisioning.github.project.visibility.enabled',
 ];
 
 export interface SamlSettingValue {