aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authorAurelien Poscia <aurelien.poscia@sonarsource.com>2023-03-10 16:23:31 +0100
committersonartech <sonartech@sonarsource.com>2023-03-22 20:04:07 +0000
commitc1b29099072474f28a30e153f80ab3d1c4f0dd41 (patch)
tree60cd78b0ff93f98f25761e6bf2c4f19005d33af9 /server/sonar-server-common
parentc711b44ab5873bd602605552b05b04a1a26b255c (diff)
downloadsonarqube-c1b29099072474f28a30e153f80ab3d1c4f0dd41.tar.gz
sonarqube-c1b29099072474f28a30e153f80ab3d1c4f0dd41.zip
SONAR-18689 add filtering by managed in /api/users/search
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/management/DelegatingManagedInstanceService.java7
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/management/ManagedInstanceService.java2
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/management/DelegatingManagedInstanceServiceTest.java28
3 files changed, 37 insertions, 0 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/management/DelegatingManagedInstanceService.java b/server/sonar-server-common/src/main/java/org/sonar/server/management/DelegatingManagedInstanceService.java
index 9bb07da8b31..8c58caf15f5 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/management/DelegatingManagedInstanceService.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/management/DelegatingManagedInstanceService.java
@@ -60,6 +60,13 @@ public class DelegatingManagedInstanceService implements ManagedInstanceService
.orElse(returnNonManagedForAllGroups(groupUuids));
}
+ @Override
+ public String getManagedUsersSqlFilter(boolean filterByManaged) {
+ return findManagedInstanceService()
+ .map(managedInstanceService -> managedInstanceService.getManagedUsersSqlFilter(filterByManaged))
+ .orElseThrow(() -> new IllegalStateException("This instance is not managed."));
+ }
+
private Optional<ManagedInstanceService> findManagedInstanceService() {
Set<ManagedInstanceService> managedInstanceServices = delegates.stream()
.filter(ManagedInstanceService::isInstanceExternallyManaged)
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/management/ManagedInstanceService.java b/server/sonar-server-common/src/main/java/org/sonar/server/management/ManagedInstanceService.java
index 581fe04e34f..942d3b5f9e4 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/management/ManagedInstanceService.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/management/ManagedInstanceService.java
@@ -32,4 +32,6 @@ public interface ManagedInstanceService {
Map<String, Boolean> getUserUuidToManaged(DbSession dbSession, Set<String> userUuids);
Map<String, Boolean> getGroupUuidToManaged(DbSession dbSession, Set<String> groupUuids);
+
+ String getManagedUsersSqlFilter(boolean filterByManaged);
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/management/DelegatingManagedInstanceServiceTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/management/DelegatingManagedInstanceServiceTest.java
index 542074300b5..e201461ec52 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/management/DelegatingManagedInstanceServiceTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/management/DelegatingManagedInstanceServiceTest.java
@@ -125,6 +125,24 @@ public class DelegatingManagedInstanceServiceTest {
.withMessage("The instance can't be managed by more than one identity provider and 2 were found.");
}
+ @Test
+ public void getManagedUsersSqlFilter_whenNoDelegates_throws() {
+ Set<ManagedInstanceService> managedInstanceServices = emptySet();
+ DelegatingManagedInstanceService delegatingManagedInstanceService = new DelegatingManagedInstanceService(managedInstanceServices);
+ assertThatIllegalStateException()
+ .isThrownBy(() -> delegatingManagedInstanceService.getManagedUsersSqlFilter(true))
+ .withMessage("This instance is not managed.");
+ }
+
+ @Test
+ public void getManagedUsersSqlFilter_delegatesToRightService_andPropagateAnswer() {
+ AlwaysManagedInstanceService alwaysManagedInstanceService = new AlwaysManagedInstanceService();
+ DelegatingManagedInstanceService managedInstanceService = new DelegatingManagedInstanceService(Set.of(new NeverManagedInstanceService(), alwaysManagedInstanceService));
+
+ assertThat(managedInstanceService.getManagedUsersSqlFilter(true)).isNotNull().isEqualTo(alwaysManagedInstanceService.getManagedUsersSqlFilter(
+ true));
+ }
+
private ManagedInstanceService getManagedInstanceService(Set<String> userUuids, Map<String, Boolean> uuidToManaged) {
ManagedInstanceService anotherManagedInstanceService = mock(ManagedInstanceService.class);
when(anotherManagedInstanceService.isInstanceExternallyManaged()).thenReturn(true);
@@ -149,6 +167,11 @@ public class DelegatingManagedInstanceServiceTest {
public Map<String, Boolean> getGroupUuidToManaged(DbSession dbSession, Set<String> groupUuids) {
return null;
}
+
+ @Override
+ public String getManagedUsersSqlFilter(boolean filterByManaged) {
+ return null;
+ }
}
private static class AlwaysManagedInstanceService implements ManagedInstanceService {
@@ -167,6 +190,11 @@ public class DelegatingManagedInstanceServiceTest {
public Map<String, Boolean> getGroupUuidToManaged(DbSession dbSession, Set<String> groupUuids) {
return null;
}
+
+ @Override
+ public String getManagedUsersSqlFilter(boolean filterByManaged) {
+ return "any filter";
+ }
}
}