]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9132 remove redundant "org-enabled" check for custom rule create
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Thu, 20 Apr 2017 11:31:58 +0000 (13:31 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Wed, 26 Apr 2017 14:03:12 +0000 (16:03 +0200)
server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java

index a1b6c0661cf915be8d3af8e330a207b72d1815fa..7f4d99b8873d37f83fc50b8b2266c5bfd564b1c3 100644 (file)
@@ -35,7 +35,6 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.db.rule.RuleParamDto;
-import org.sonar.server.organization.OrganizationFlags;
 import org.sonar.server.rule.NewCustomRule;
 import org.sonar.server.rule.ReactivationException;
 import org.sonar.server.rule.RuleCreator;
@@ -64,14 +63,12 @@ public class CreateAction implements RulesWsAction {
   private final DbClient dbClient;
   private final RuleCreator ruleCreator;
   private final RuleMapper ruleMapper;
-  private final OrganizationFlags organizationFlags;
   private final RuleWsSupport ruleWsSupport;
 
-  public CreateAction(DbClient dbClient, RuleCreator ruleCreator, RuleMapper ruleMapper, OrganizationFlags organizationFlags, RuleWsSupport ruleWsSupport) {
+  public CreateAction(DbClient dbClient, RuleCreator ruleCreator, RuleMapper ruleMapper, RuleWsSupport ruleWsSupport) {
     this.dbClient = dbClient;
     this.ruleCreator = ruleCreator;
     this.ruleMapper = ruleMapper;
-    this.organizationFlags = organizationFlags;
     this.ruleWsSupport = ruleWsSupport;
   }
 
@@ -83,8 +80,7 @@ public class CreateAction implements RulesWsAction {
         "Requires the 'Administer Quality Profiles' permission")
       .setSince("4.4")
       .setChangelog(
-        new Change("5.5", "Creating manual rule is not more possible"),
-        new Change("6.4", "Creating custom rules are not supported if the organization feature is enabled. In that case, the webservice will fail"))
+        new Change("5.5", "Creating manual rule is not more possible"))
       .setPost(true)
       .setHandler(this);
 
@@ -143,7 +139,6 @@ public class CreateAction implements RulesWsAction {
     ruleWsSupport.checkQProfileAdminPermission();
     String customKey = request.mandatoryParam(PARAM_CUSTOM_KEY);
     try (DbSession dbSession = dbClient.openSession(false)) {
-      organizationFlags.checkDisabled(dbSession);
       try {
         NewCustomRule newRule = NewCustomRule.createForCustomRule(customKey, RuleKey.parse(request.mandatoryParam(PARAM_TEMPLATE_KEY)))
           .setName(request.mandatoryParam(PARAM_NAME))
index 11731c7dc1c8c80543ea1784018d66b9b0fe093b..2e66cde28c795bc4b2b2349cd4c538417fbf72e1 100644 (file)
@@ -36,7 +36,6 @@ import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.organization.DefaultOrganizationProvider;
 import org.sonar.server.organization.TestDefaultOrganizationProvider;
-import org.sonar.server.organization.TestOrganizationFlags;
 import org.sonar.server.rule.RuleCreator;
 import org.sonar.server.rule.index.RuleIndexDefinition;
 import org.sonar.server.rule.index.RuleIndexer;
@@ -72,19 +71,17 @@ public class CreateActionTest {
   @Rule
   public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings()));
 
-  private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone();
   private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
 
   private WsActionTester ws = new WsActionTester(new CreateAction(db.getDbClient(),
     new RuleCreator(system2, new RuleIndexer(es.client(), db.getDbClient()), db.getDbClient(), newFullTypeValidations(),
       TestDefaultOrganizationProvider.from(db)),
-    new RuleMapper(new Languages(), createMacroInterpreter()), organizationFlags,
+    new RuleMapper(new Languages(), createMacroInterpreter()),
     new RuleWsSupport(db.getDbClient(), userSession, defaultOrganizationProvider)));
 
   @Test
   public void create_custom_rule() {
     logInAsQProfileAdministrator();
-    organizationFlags.setEnabled(false);
     // Template rule
     RuleDto templateRule = newTemplateRule(RuleKey.of("java", "S001"), db.getDefaultOrganization());
     db.rules().insert(templateRule.getDefinition());
@@ -129,7 +126,6 @@ public class CreateActionTest {
   @Test
   public void create_custom_rule_with_prevent_reactivation_param_to_true() {
     logInAsQProfileAdministrator();
-    organizationFlags.setEnabled(false);
     RuleDefinitionDto templateRule = newTemplateRule(RuleKey.of("java", "S001")).getDefinition();
     db.rules().insert(templateRule);
     // insert a removed rule
@@ -165,23 +161,6 @@ public class CreateActionTest {
       "}\n");
   }
 
-  @Test
-  public void fail_to_create_rule_when_organizations_are_enabled() throws Exception {
-    logInAsQProfileAdministrator();
-    organizationFlags.setEnabled(true);
-
-    expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage("Organization support is enabled");
-
-    ws.newRequest()
-      .setParam("custom_key", "MY_CUSTOM")
-      .setParam("template_key", "java:S001")
-      .setParam("name", "My custom rule")
-      .setParam("markdown_description", "Description")
-      .setParam("severity", "MAJOR")
-      .execute();
-  }
-
   @Test
   public void throw_ForbiddenException_if_not_profile_administrator() throws Exception {
     userSession.logIn();