]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21179 Deprecate preventReactivation param
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>
Fri, 8 Dec 2023 06:32:13 +0000 (07:32 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 8 Dec 2023 20:03:05 +0000 (20:03 +0000)
server/sonar-webserver-common/src/main/java/org/sonar/server/common/rule/RuleCreator.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/RuleUpdaterIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/RuleUpdater.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/CreateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java

index 9fabf6770930b3b5c180d8646702f1bb05aa6554..853cfd0c98408549e17f92992433c1fcf5f00b5a 100644 (file)
@@ -91,7 +91,7 @@ public class RuleCreator {
     validateCustomRule(newRule, dbSession, templateKey);
 
     Optional<RuleDto> definition = loadRule(dbSession, newRule.ruleKey());
-    RuleDto ruleDto = definition.map(d -> updateExistingRule(d, newRule, dbSession))
+    RuleDto ruleDto = definition.map(dto -> updateExistingRule(dto, newRule, dbSession))
       .orElseGet(() -> createCustomRule(newRule, templateRule, dbSession));
 
     ruleIndexer.commitAndIndex(dbSession, ruleDto.getUuid());
index 46de88eb5309909521e414fca38a0960989923ae..9c6f69672ed28ae257f0e8ed83984827e33cffc5 100644 (file)
@@ -59,6 +59,7 @@ import org.sonar.server.rule.index.RuleQuery;
 import org.sonar.server.tester.UserSessionRule;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatNoException;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.rule.Severity.CRITICAL;
@@ -91,18 +92,19 @@ public class RuleUpdaterIT {
   private final RuleUpdater underTest = new RuleUpdater(db.getDbClient(), ruleIndexer, uuidFactory, system2);
 
   @Test
-  public void do_not_update_rule_with_removed_status() {
+  public void do_update_rule_with_removed_status() {
     db.rules().insert(newRule(RULE_KEY).setStatus(RuleStatus.REMOVED));
     dbSession.commit();
 
-    RuleUpdate update = createForPluginRule(RULE_KEY)
-      .setTags(Sets.newHashSet("java9"));
+    RuleUpdate update = createForCustomRule(RULE_KEY)
+      .setTags(Sets.newHashSet("java9"))
+      .setStatus(RuleStatus.READY);
 
-    assertThatThrownBy(() -> {
-      underTest.update(dbSession, update, userSessionRule);
-    })
-      .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Rule with REMOVED status cannot be updated: java:S001");
+    assertThatNoException().isThrownBy(() -> underTest.update(dbSession, update, userSessionRule));
+    RuleDto rule = db.getDbClient().ruleDao().selectOrFailByKey(dbSession, RULE_KEY);
+
+    assertThat(rule.getTags()).containsOnly("java9");
+    assertThat(rule.getStatus()).isEqualTo(RuleStatus.READY);
   }
 
   @Test
index 1d0d4a14464a2b146dd7deb5142eaf13c6270393..381363c45184effb364638726d33bc10a6264ebf 100644 (file)
@@ -95,11 +95,7 @@ public class RuleUpdater {
    */
   private RuleDto getRuleDto(RuleUpdate change) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      RuleDto rule = dbClient.ruleDao().selectOrFailByKey(dbSession, change.getRuleKey());
-      if (RuleStatus.REMOVED == rule.getStatus()) {
-        throw new IllegalArgumentException("Rule with REMOVED status cannot be updated: " + change.getRuleKey());
-      }
-      return rule;
+      return dbClient.ruleDao().selectOrFailByKey(dbSession, change.getRuleKey());
     }
   }
 
index 121b32594eeb80df27a0ccec183c8b1d172c433b..b83a7b36fb3cb7e837df4ed1cff2b60d108dd2fd 100644 (file)
@@ -65,10 +65,15 @@ public class CreateAction implements RulesWsAction {
   private static final String PARAM_CLEAN_CODE_ATTRIBUTE = "cleanCodeAttribute";
   public static final String PARAMS = "params";
 
-  public static final String PARAM_PREVENT_REACTIVATION = "preventReactivation";
   static final int KEY_MAXIMUM_LENGTH = 200;
   static final int NAME_MAXIMUM_LENGTH = 200;
 
+  /**
+   * @deprecated since 10.4
+   */
+  @Deprecated(since = "10.4")
+  private static final String PARAM_PREVENT_REACTIVATION = "preventReactivation";
+
   private final DbClient dbClient;
   private final RuleService ruleService;
   private final RuleMapper ruleMapper;
@@ -96,7 +101,8 @@ public class CreateAction implements RulesWsAction {
         new Change("10.2", "Add 'impacts', 'cleanCodeAttribute', 'cleanCodeAttributeCategory' fields to the response"),
         new Change("10.2", "Fields 'type' and 'severity' are deprecated in the response. Use 'impacts' instead."),
         new Change("10.4", String.format("Add '%s' and '%s' parameters to the request", PARAM_IMPACTS, PARAM_CLEAN_CODE_ATTRIBUTE)),
-        new Change("10.4", String.format("Parameters '%s' and '%s' are deprecated. Use '%s' instead.", PARAM_TYPE, PARAM_SEVERITY, PARAM_IMPACTS)))
+        new Change("10.4", String.format("Parameters '%s' and '%s' are deprecated. Use '%s' instead.", PARAM_TYPE, PARAM_SEVERITY, PARAM_IMPACTS)),
+        new Change("10.4", String.format("Parameter '%s' is deprecated. Use api/rules/update endpoint instead.", PARAM_PREVENT_REACTIVATION)))
       .setHandler(this);
 
     action
@@ -146,6 +152,7 @@ public class CreateAction implements RulesWsAction {
 
     action
       .createParam(PARAM_PREVENT_REACTIVATION)
+      .setDeprecatedSince("10.4")
       .setBooleanPossibleValues()
       .setDefaultValue(false)
       .setDescription("If set to true and if the rule has been deactivated (status 'REMOVED'), a status 409 will be returned");
index 608d726fd07c1863af1d18b847e00b802395f459..8af573cf247fab9a8e8efe9486e27d3b305aaf6a 100644 (file)
@@ -91,7 +91,8 @@ public class UpdateAction implements RulesWsAction {
       .setDescription("Update an existing rule.<br>" +
         "Requires the 'Administer Quality Profiles' permission")
       .setChangelog(
-        new Change("10.2", "The field 'severity' and 'type' in the response have been deprecated, use 'impacts' instead.")
+        new Change("10.2", "The field 'severity' and 'type' in the response have been deprecated, use 'impacts' instead."),
+        new Change("10.4", "Updating a removed rule is now possible.")
       )
       .setSince("4.4")
       .setChangelog(