aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-common
diff options
context:
space:
mode:
authorWojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com>2024-01-04 14:19:16 +0100
committersonartech <sonartech@sonarsource.com>2024-01-04 20:02:48 +0000
commit5efcc863cf8f76e37218713945f791e6963754ad (patch)
treecca2b36532b0b6082fdac37c82a89fa927fd9ccf /server/sonar-webserver-common
parent2cf35e5bd9752e86cd34457e4bb58548e036d709 (diff)
downloadsonarqube-5efcc863cf8f76e37218713945f791e6963754ad.tar.gz
sonarqube-5efcc863cf8f76e37218713945f791e6963754ad.zip
SONAR-21244 Allow deletion of local groups when instance is managed.
Diffstat (limited to 'server/sonar-webserver-common')
-rw-r--r--server/sonar-webserver-common/src/main/java/org/sonar/server/common/management/ManagedInstanceChecker.java4
-rw-r--r--server/sonar-webserver-common/src/test/java/com/sonar/server/common/management/ManagedInstanceCheckerTest.java17
2 files changed, 21 insertions, 0 deletions
diff --git a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/management/ManagedInstanceChecker.java b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/management/ManagedInstanceChecker.java
index fa2f70c6539..dad6f4ac6d2 100644
--- a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/management/ManagedInstanceChecker.java
+++ b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/management/ManagedInstanceChecker.java
@@ -49,6 +49,10 @@ public class ManagedInstanceChecker {
BadRequestException.checkRequest(!managedInstanceService.isUserManaged(dbSession, userUuid), INSTANCE_EXCEPTION_MESSAGE);
}
+ public void throwIfGroupIsManaged(DbSession dbSession, String groupUuid) {
+ BadRequestException.checkRequest(!managedInstanceService.isGroupManaged(dbSession, groupUuid), INSTANCE_EXCEPTION_MESSAGE);
+ }
+
public void throwIfUserAndProjectAreManaged(DbSession dbSession, String userUuid, String projectUuid) {
boolean isUserManaged = managedInstanceService.isUserManaged(dbSession, userUuid);
boolean isProjectManaged = managedProjectService.isProjectManaged(dbSession, projectUuid);
diff --git a/server/sonar-webserver-common/src/test/java/com/sonar/server/common/management/ManagedInstanceCheckerTest.java b/server/sonar-webserver-common/src/test/java/com/sonar/server/common/management/ManagedInstanceCheckerTest.java
index f96a624f860..83b3c732707 100644
--- a/server/sonar-webserver-common/src/test/java/com/sonar/server/common/management/ManagedInstanceCheckerTest.java
+++ b/server/sonar-webserver-common/src/test/java/com/sonar/server/common/management/ManagedInstanceCheckerTest.java
@@ -104,6 +104,23 @@ public class ManagedInstanceCheckerTest {
}
@Test
+ public void throwIfGroupIsManaged_whenGroupIsManaged_shouldThrow() {
+ GroupDto groupDto = mockManagedGroup();
+
+ String groupUuid = groupDto.getUuid();
+ assertThatThrownBy(() -> managedInstanceChecker.throwIfGroupIsManaged(dbSession, groupUuid))
+ .isInstanceOf(BadRequestException.class)
+ .hasMessage(INSTANCE_EXCEPTION_MESSAGE);
+ }
+
+ @Test
+ public void throwIfGroupIsManaged_whenGroupIsNotManaged_shouldNotThrow() {
+ GroupDto groupDto = mockNotManagedGroup();
+
+ assertThatNoException().isThrownBy(() -> managedInstanceChecker.throwIfGroupIsManaged(dbSession, groupDto.getUuid()));
+ }
+
+ @Test
public void throwIfUserAndProjectAreManaged_whenUserAndProjectAreManaged_shouldThrow() {
ProjectDto projectDto = mockManagedProject();
UserDto userDto = mockManagedUser();