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;
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;
}
"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);
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))
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;
@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());
@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
"}\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();