]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19085 Add managed groups SQL filter.
authorWojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com>
Mon, 8 May 2023 12:51:01 +0000 (14:51 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 11 May 2023 20:03:14 +0000 (20:03 +0000)
server/sonar-db-dao/src/it/java/org/sonar/db/user/ExternalGroupDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/user/ExternalGroupDao.java

index baa685e0ab9331cbacccb4653c049a69eb32a13f..26d47127977454fe9c0790aa29a6fdee1f73172d 100644 (file)
@@ -69,6 +69,18 @@ public class ExternalGroupDaoIT {
     assertThat(remainingGroups).containsExactlyInAnyOrderElementsOf(insertedGroups);
   }
 
+  @Test
+  public void getManagedGroupsSqlFilter_whenFilterByManagedIsTrue_returnsCorrectQuery() {
+    String filterManagedUser = underTest.getManagedGroupSqlFilter(true);
+    assertThat(filterManagedUser).isEqualTo(" exists (select group_uuid from external_groups eg where eg.group_uuid = uuid)");
+  }
+
+  @Test
+  public void getManagedGroupsSqlFilter_whenFilterByManagedIsFalse_returnsCorrectQuery() {
+    String filterNonManagedUser = underTest.getManagedGroupSqlFilter(false);
+    assertThat(filterNonManagedUser).isEqualTo("not exists (select group_uuid from external_groups eg where eg.group_uuid = uuid)");
+  }
+
   private List<ExternalGroupDto> createAndInsertExternalGroupDtos(String provider, int numberOfGroups) {
     List<ExternalGroupDto> expectedExternalGroupDtos = new ArrayList<>();
     for (int i = 1; i <= numberOfGroups; i++) {
index c6c95692efa73aa227f46b7d72aa2106b2f9b578..9980aaa60ceffbc24ccb0d38bc52fcfc50c304fc 100644 (file)
@@ -40,4 +40,8 @@ public class ExternalGroupDao implements Dao {
   private static ExternalGroupMapper mapper(DbSession session) {
     return session.getMapper(ExternalGroupMapper.class);
   }
+
+  public String getManagedGroupSqlFilter(boolean filterByManaged) {
+    return String.format("%s exists (select group_uuid from external_groups eg where eg.group_uuid = uuid)", filterByManaged ? "" : "not");
+  }
 }