aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-07-03 11:43:09 +0200
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>2017-07-04 15:53:24 +0200
commit72f20e1066197e64b7e5d348d9f1bc2466073f2e (patch)
tree90bb14fcb12ec04fc869a4833c697568f8206932
parent247acabe5af48c07fe0079eacecb9b9741512b59 (diff)
downloadsonarqube-72f20e1066197e64b7e5d348d9f1bc2466073f2e.tar.gz
sonarqube-72f20e1066197e64b7e5d348d9f1bc2466073f2e.zip
SONAR-9432 let rule search use OR instead of AND when filtering by tags
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java43
2 files changed, 44 insertions, 1 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
index 8638e255fa8..7a623e10dd8 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
@@ -256,7 +256,7 @@ public class RuleIndex {
.filter(QueryBuilders.termQuery(FIELD_RULE_EXTENSION_TAGS, tag))
.filter(termsQuery(FIELD_RULE_EXTENSION_SCOPE, RuleExtensionScope.system().getScope(), RuleExtensionScope.organization(query.getOrganization()).getScope())))
.map(childQuery -> QueryBuilders.hasChildQuery(INDEX_TYPE_RULE_EXTENSION.getType(), childQuery))
- .forEach(q::filter);
+ .forEach(q::should);
filters.put(FIELD_RULE_EXTENSION_TAGS, q);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java
index 8b2c610a6dd..1d5507795ea 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java
@@ -223,6 +223,26 @@ public class SearchActionTest {
}
@Test
+ public void when_searching_for_several_tags_combine_them_with_OR() throws IOException {
+ OrganizationDto organization = dbTester.organizations().insert();
+ RuleDefinitionDto bothTagsRule = createJavaRule();
+ insertMetadata(organization, bothTagsRule, setTags("tag1", "tag2"));
+ RuleDefinitionDto oneTagRule = createJavaRule();
+ insertMetadata(organization, oneTagRule, setTags("tag1"));
+ RuleDefinitionDto otherTagRule = createJavaRule();
+ insertMetadata(organization, otherTagRule, setTags("tag2"));
+ RuleDefinitionDto noTagRule = createJavaRule();
+ insertMetadata(organization, noTagRule, setTags());
+ indexRules();
+
+ Consumer<TestRequest> request = r -> r
+ .setParam("f", "repo,name")
+ .setParam("tags", "tag1,tag2")
+ .setParam("organization", organization.getKey());
+ verify(request, bothTagsRule, oneTagRule, otherTagRule);
+ }
+
+ @Test
public void should_list_tags_in_tags_facet() throws IOException {
OrganizationDto organization = dbTester.organizations().insert();
RuleDefinitionDto rule = dbTester.rules().insert(setSystemTags("tag1", "tag3", "tag5", "tag7", "tag9", "x"));
@@ -280,6 +300,29 @@ public class SearchActionTest {
}
@Test
+ public void should_not_return_tags_of_foreign_organization() throws IOException {
+ OrganizationDto organizationWithSpecificTags = dbTester.organizations().insert();
+ OrganizationDto myOrganization = dbTester.organizations().insert();
+ RuleDefinitionDto rule = dbTester.rules().insert(setSystemTags("system1", "system2"));
+ insertMetadata(organizationWithSpecificTags, rule, setTags("tag1", "tag2"));
+ indexRules();
+
+ SearchResponse result = ws.newRequest()
+ .setParam("facets", "tags")
+ .setParam("f", "tags")
+ .setParam("organization", myOrganization.getKey())
+ .executeProtobuf(SearchResponse.class);
+
+ assertThat(result.getRulesList()).extracting(Rule::getKey).containsExactly(rule.getKey().toString());
+ assertThat(result.getFacets().getFacets(0).getValuesList())
+ .extracting(v -> tuple(v.getVal(), v.getCount()))
+ .containsExactly(
+ tuple("system1", 1L),
+ tuple("system2", 1L)
+ );
+ }
+
+ @Test
public void should_return_specified_fields() throws Exception {
RuleDefinitionDto rule = createJavaRule();
indexRules();