]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13999 drop organization from Rule WS
authorJacek <jacek.poreda@sonarsource.com>
Wed, 16 Dec 2020 14:44:44 +0000 (15:44 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 22 Dec 2020 20:09:37 +0000 (20:09 +0000)
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/DeleteAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RulesWsParameters.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/ShowAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/UpdateAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/TagsActionTest.java

index a1d6c9728517ca9a0986142370221cd83c4f665c..dafd4bf2f6f5425b0ea7862c01cd7001d1dbfcb6 100644 (file)
@@ -141,7 +141,7 @@ public class CreateAction implements RulesWsAction {
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    ruleWsSupport.checkQProfileAdminPermissionOnDefaultOrganization();
+    ruleWsSupport.checkQProfileAdminPermission();
     String customKey = request.mandatoryParam(PARAM_CUSTOM_KEY);
     try (DbSession dbSession = dbClient.openSession(false)) {
       try {
index b0a4364c91ac2b4170beafb4ece8dfebf0368eb1..5da3cf009ae2d355d44fa5bb81746f731ca7cec0 100644 (file)
@@ -70,7 +70,7 @@ public class DeleteAction implements RulesWsAction {
 
   @Override
   public void handle(Request request, Response response) {
-    ruleWsSupport.checkQProfileAdminPermissionOnDefaultOrganization();
+    ruleWsSupport.checkQProfileAdminPermission();
     RuleKey key = RuleKey.parse(request.mandatoryParam(PARAM_KEY));
     delete(key);
   }
index 11c106e8026e6a2de56290730e2733923547b074..56f6e84cad9b1e27f24305cd86fa0e56080cf347 100644 (file)
@@ -80,7 +80,7 @@ public class RuleWsSupport {
     this.userSession = userSession;
   }
 
-  public void checkQProfileAdminPermissionOnDefaultOrganization() {
+  public void checkQProfileAdminPermission() {
     userSession
       .checkLoggedIn()
       .checkPermission(ADMINISTER_QUALITY_PROFILES);
index 2403c3bfe13c36ffcfbd87c5fe62bdd7b37571eb..5e365d7099dec3ca34a84f438c7d80dbba38cf50 100644 (file)
@@ -42,7 +42,6 @@ public class RulesWsParameters {
   public static final String PARAM_IS_TEMPLATE = "is_template";
   public static final String PARAM_INCLUDE_EXTERNAL = "include_external";
   public static final String PARAM_TEMPLATE_KEY = "template_key";
-  public static final String PARAM_ORGANIZATION = "organization";
   public static final String PARAM_COMPARE_TO_PROFILE = "compareToProfile";
 
   public static final String FIELD_REPO = "repo";
index 6ea78b916750b369ddb6398b2e2a1f1647891615..c446d987d4a76214ffade49890a58f1a441a5be4 100644 (file)
@@ -46,7 +46,6 @@ public class ShowAction implements RulesWsAction {
 
   public static final String PARAM_KEY = "key";
   public static final String PARAM_ACTIVES = "actives";
-  public static final String PARAM_ORGANIZATION = "organization";
 
   private final DbClient dbClient;
   private final RuleMapper mapper;
index b07bdd50bb818a32f7e77c419ce3592604748a1e..6cdec3591db2720b72e9f7a0caf12e04aef9b5ec 100644 (file)
@@ -156,7 +156,7 @@ public class UpdateAction implements RulesWsAction {
   public void handle(Request request, Response response) throws Exception {
     userSession.checkLoggedIn();
     try (DbSession dbSession = dbClient.openSession(false)) {
-      ruleWsSupport.checkQProfileAdminPermissionOnDefaultOrganization();
+      ruleWsSupport.checkQProfileAdminPermission();
       RuleUpdate update = readRequest(dbSession, request);
       ruleUpdater.update(dbSession, update, userSession);
       UpdateResponse updateResponse = buildResponse(dbSession, update.getRuleKey());
index 0f65e4760aadb68cfabf15a22da09cc1312c3601..e8828245f91bb433674130a8471c940ee97a8b2f 100644 (file)
@@ -37,7 +37,6 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.qualityprofile.ActiveRuleParamDto;
 import org.sonar.db.qualityprofile.QProfileDto;
 import org.sonar.db.rule.RuleDefinitionDto;
@@ -83,7 +82,6 @@ import static org.sonar.db.rule.RuleTesting.setSystemTags;
 import static org.sonar.db.rule.RuleTesting.setTags;
 import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_ACTIVATION;
 import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_COMPARE_TO_PROFILE;
-import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_ORGANIZATION;
 import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_QPROFILE;
 import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_RULE_KEY;
 
@@ -96,26 +94,26 @@ public class SearchActionTest {
   @org.junit.Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private System2 system2 = new AlwaysIncreasingSystem2();
+  private final System2 system2 = new AlwaysIncreasingSystem2();
   @org.junit.Rule
   public DbTester db = DbTester.create(system2);
   @org.junit.Rule
   public EsTester es = EsTester.create();
 
-  private RuleIndex ruleIndex = new RuleIndex(es.client(), system2);
-  private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
-  private ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(db.getDbClient(), es.client());
-  private Languages languages = LanguageTesting.newLanguages(JAVA, "js");
-  private ActiveRuleCompleter activeRuleCompleter = new ActiveRuleCompleter(db.getDbClient(), languages);
-  private RuleQueryFactory ruleQueryFactory = new RuleQueryFactory(db.getDbClient());
-  private MacroInterpreter macroInterpreter = mock(MacroInterpreter.class);
-  private RuleMapper ruleMapper = new RuleMapper(languages, macroInterpreter);
-  private SearchAction underTest = new SearchAction(ruleIndex, activeRuleCompleter, ruleQueryFactory, db.getDbClient(), ruleMapper,
+  private final RuleIndex ruleIndex = new RuleIndex(es.client(), system2);
+  private final RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
+  private final ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(db.getDbClient(), es.client());
+  private final Languages languages = LanguageTesting.newLanguages(JAVA, "js");
+  private final ActiveRuleCompleter activeRuleCompleter = new ActiveRuleCompleter(db.getDbClient(), languages);
+  private final RuleQueryFactory ruleQueryFactory = new RuleQueryFactory(db.getDbClient());
+  private final MacroInterpreter macroInterpreter = mock(MacroInterpreter.class);
+  private final RuleMapper ruleMapper = new RuleMapper(languages, macroInterpreter);
+  private final SearchAction underTest = new SearchAction(ruleIndex, activeRuleCompleter, ruleQueryFactory, db.getDbClient(), ruleMapper,
     new RuleWsSupport(db.getDbClient(), userSession));
-  private TypeValidations typeValidations = new TypeValidations(asList(new StringTypeValidation(), new IntegerTypeValidation()));
-  private RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, db.getDbClient(), typeValidations, userSession);
-  private QProfileRules qProfileRules = new QProfileRulesImpl(db.getDbClient(), ruleActivator, ruleIndex, activeRuleIndexer);
-  private WsActionTester ws = new WsActionTester(underTest);
+  private final TypeValidations typeValidations = new TypeValidations(asList(new StringTypeValidation(), new IntegerTypeValidation()));
+  private final RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, db.getDbClient(), typeValidations, userSession);
+  private final QProfileRules qProfileRules = new QProfileRulesImpl(db.getDbClient(), ruleActivator, ruleIndex, activeRuleIndexer);
+  private final WsActionTester ws = new WsActionTester(underTest);
 
   @Before
   public void before() {
@@ -162,7 +160,6 @@ public class SearchActionTest {
 
   @Test
   public void return_note_login() {
-    OrganizationDto organization = db.organizations().insert();
     UserDto user1 = db.users().insertUser();
     RuleDefinitionDto rule1 = db.rules().insert();
     db.rules().insertOrUpdateMetadata(rule1, user1);
@@ -173,7 +170,6 @@ public class SearchActionTest {
 
     SearchResponse result = ws.newRequest()
       .setParam("f", "noteLogin")
-      .setParam("organization", organization.getKey())
       .executeProtobuf(SearchResponse.class);
 
     assertThat(result.getRulesList())
@@ -390,7 +386,7 @@ public class SearchActionTest {
   }
 
   @Test
-  public void should_return_organization_specific_tags() {
+  public void should_return_specific_tags() {
     RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java"));
     RuleMetadataDto metadata = insertMetadata(rule, setTags("tag1", "tag2"));
     indexRules();
@@ -426,7 +422,6 @@ public class SearchActionTest {
 
   @Test
   public void return_lang_key_field_when_language_name_is_not_available() {
-    OrganizationDto organization = db.organizations().insert();
     String unknownLanguage = "unknown_" + randomAlphanumeric(5);
     RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(unknownLanguage));
 
@@ -434,7 +429,6 @@ public class SearchActionTest {
 
     SearchResponse result = ws.newRequest()
       .setParam("f", "langName")
-      .setParam("organization", organization.getKey())
       .executeProtobuf(SearchResponse.class);
     assertThat(result.getTotal()).isEqualTo(1);
     assertThat(result.getRulesCount()).isEqualTo(1);
@@ -603,7 +597,6 @@ public class SearchActionTest {
 
   @Test
   public void search_all_active_rules() {
-    OrganizationDto organization = db.organizations().insert();
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage("java"));
     RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java"));
     RuleActivation activation = RuleActivation.create(rule.getUuid(), BLOCKER, null);
@@ -614,7 +607,6 @@ public class SearchActionTest {
     SearchResponse result = ws.newRequest()
       .setParam("q", rule.getName())
       .setParam("activation", "true")
-      .setParam("organization", organization.getKey())
       .executeProtobuf(SearchResponse.class);
     assertThat(result.getTotal()).isEqualTo(1);
     assertThat(result.getRulesCount()).isEqualTo(1);
@@ -627,7 +619,6 @@ public class SearchActionTest {
 
   @Test
   public void search_profile_active_rules() {
-    OrganizationDto organization = db.organizations().insert();
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage("java"));
     QProfileDto waterproofProfile = db.qualityProfiles().insert(p -> p.setLanguage("java"));
     RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java"));
@@ -657,7 +648,6 @@ public class SearchActionTest {
     SearchResponse result = ws.newRequest()
       .setParam("f", "actives")
       .setParam("q", rule.getName())
-      .setParam("organization", organization.getKey())
       .setParam("activation", "true")
       .setParam("qprofile", profile.getKee())
       .executeProtobuf(SearchResponse.class);
@@ -686,7 +676,6 @@ public class SearchActionTest {
 
   @Test
   public void search_for_active_rules_when_parameter_value_is_null() {
-    OrganizationDto organization = db.organizations().insert();
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage("java"));
 
     RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage("java"));
@@ -711,7 +700,6 @@ public class SearchActionTest {
     SearchResponse result = ws.newRequest()
       .setParam("f", "actives")
       .setParam("q", rule.getName())
-      .setParam("organization", organization.getKey())
       .setParam("activation", "true")
       .setParam("qprofile", profile.getKee())
       .executeProtobuf(SearchResponse.class);
@@ -735,8 +723,6 @@ public class SearchActionTest {
    */
   @Test
   public void facet_filtering_when_searching_for_inactive_rules() {
-    OrganizationDto organization = db.organizations().insert();
-
     QProfileDto profile = db.qualityProfiles().insert(q -> q.setLanguage("language1"));
 
     // on same language, not activated => match
@@ -773,7 +759,6 @@ public class SearchActionTest {
 
     SearchResponse result = ws.newRequest()
       .setParam("facets", "languages,repositories,tags,severities,statuses,types")
-      .setParam("organization", organization.getKey())
       .setParam("activation", "false")
       .setParam("qprofile", profile.getKee())
       .executeProtobuf(SearchResponse.class);
@@ -854,7 +839,6 @@ public class SearchActionTest {
 
   @Test
   public void compare_to_another_profile() {
-    OrganizationDto organization = db.organizations().insert();
     QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(JAVA));
     QProfileDto anotherProfile = db.qualityProfiles().insert(p -> p.setLanguage(JAVA));
     RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(JAVA)).getDefinition();
@@ -874,7 +858,6 @@ public class SearchActionTest {
     indexActiveRules();
 
     SearchResponse result = ws.newRequest()
-      .setParam(PARAM_ORGANIZATION, organization.getKey())
       .setParam(PARAM_QPROFILE, profile.getKee())
       .setParam(PARAM_ACTIVATION, "false")
       .setParam(PARAM_COMPARE_TO_PROFILE, anotherProfile.getKee())
index 295f7eabab5c9ef93e944f10dd7a8a884171f9b8..9a2bc1fc0ae685c468d64c584dfd791a1c29bb37 100644 (file)
@@ -25,7 +25,6 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.server.es.EsClient;
 import org.sonar.server.es.EsTester;
@@ -48,14 +47,12 @@ public class TagsActionTest {
   @Rule
   public EsTester es = EsTester.create();
 
-  private DbClient dbClient = db.getDbClient();
-  private EsClient esClient = es.client();
-  private RuleIndex ruleIndex = new RuleIndex(esClient, System2.INSTANCE);
-  private RuleIndexer ruleIndexer = new RuleIndexer(esClient, dbClient);
+  private final DbClient dbClient = db.getDbClient();
+  private final EsClient esClient = es.client();
+  private final RuleIndex ruleIndex = new RuleIndex(esClient, System2.INSTANCE);
+  private final RuleIndexer ruleIndexer = new RuleIndexer(esClient, dbClient);
 
-  private WsActionTester ws = new WsActionTester(new org.sonar.server.rule.ws.TagsAction(ruleIndex));
-
-  private OrganizationDto organization;
+  private final WsActionTester ws = new WsActionTester(new org.sonar.server.rule.ws.TagsAction(ruleIndex));
 
   @Test
   public void definition() {