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());
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;
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
*/
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());
}
}
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;
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
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");
.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(