@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;
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(
.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());
}
}
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() {
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()
"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() {