diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-10 15:23:49 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-10 23:07:22 +0100 |
commit | 78b2ca003cee36555b69362515d2b4d34d809031 (patch) | |
tree | f256a064368e96c08adb71c1479dea6ba9ff115d /server/sonar-server/src | |
parent | bdf3fea54eccaf98c9fed3e8a488e16588499c1d (diff) | |
download | sonarqube-78b2ca003cee36555b69362515d2b4d34d809031.tar.gz sonarqube-78b2ca003cee36555b69362515d2b4d34d809031.zip |
SONAR-8761 do not fail if org feature is already enabled
Diffstat (limited to 'server/sonar-server/src')
2 files changed, 13 insertions, 14 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/EnableSupportAction.java b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/EnableSupportAction.java index dc7f198e01d..60427f8cb93 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/EnableSupportAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/EnableSupportAction.java @@ -24,7 +24,6 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbSession; -import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.organization.OrganizationFlags; import org.sonar.server.user.UserSession; @@ -64,10 +63,11 @@ public class EnableSupportAction implements OrganizationsAction { public void handle(Request request, Response response) throws Exception { try (DbSession dbSession = dbClient.openSession(false)) { verifySystemAdministrator(); - verifyFeatureIsDisabled(dbSession); - flagCurrentUserAsRoot(dbSession); - enableFeature(dbSession); - dbSession.commit(); + if (isSupportDisabled(dbSession)) { + flagCurrentUserAsRoot(dbSession); + enableFeature(dbSession); + dbSession.commit(); + } } response.noContent(); } @@ -76,10 +76,8 @@ public class EnableSupportAction implements OrganizationsAction { userSession.checkLoggedIn().checkOrganizationPermission(defaultOrganizationProvider.get().getUuid(), SYSTEM_ADMIN); } - private void verifyFeatureIsDisabled(DbSession dbSession) { - if (organizationFlags.isEnabled(dbSession)) { - throw new BadRequestException("Organizations are already enabled"); - } + private boolean isSupportDisabled(DbSession dbSession) { + return !organizationFlags.isEnabled(dbSession); } private void flagCurrentUserAsRoot(DbSession dbSession) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/EnableSupportActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/EnableSupportActionTest.java index 0f55aeef8bd..6f03cc442e1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/EnableSupportActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/EnableSupportActionTest.java @@ -26,7 +26,6 @@ import org.junit.rules.ExpectedException; import org.sonar.api.server.ws.WebService; import org.sonar.db.DbTester; import org.sonar.db.user.UserDto; -import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.organization.DefaultOrganizationProvider; @@ -92,15 +91,17 @@ public class EnableSupportActionTest { } @Test - public void throw_BadRequestException_if_support_is_already_enabled() { + public void do_nothing_if_support_is_already_enabled() { logInAsSystemAdministrator("foo"); call(); + verifyFeatureEnabled(true); - expectedException.expect(BadRequestException.class); - expectedException.expectMessage("Organizations are already enabled"); - + // the test could be improved to verify that + // the caller user is not flagged as root + // if he was not already root call(); + verifyFeatureEnabled(true); } @Test |