From 3f9ed2570796ab50e6684198721c6e43f5fc5be2 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 7 Jun 2013 17:53:48 +0200 Subject: [PATCH] SONAR-3755 Role required to find issues should be USER instead of CODE VIEWER --- .../java/org/sonar/api/issue/IssueQuery.java | 3 +- .../org/sonar/api/issue/IssueQueryTest.java | 4 +- .../server/issue/PublicRubyIssueService.java | 50 +++++++++++-------- .../issue/PublicRubyIssueServiceTest.java | 16 +++++- 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java index 761c2b8294f..5daf278f46a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java @@ -27,6 +27,7 @@ import org.sonar.api.web.UserRole; import javax.annotation.CheckForNull; import javax.annotation.Nullable; + import java.util.Collection; import java.util.Date; import java.util.Set; @@ -218,7 +219,7 @@ public class IssueQuery { private Boolean asc = false; private Integer pageSize; private Integer pageIndex; - private String requiredRole = UserRole.CODEVIEWER; + private String requiredRole = UserRole.USER; private Builder() { } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java index 5792dc0f63a..3ee45572a6c 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/IssueQueryTest.java @@ -52,7 +52,7 @@ public class IssueQueryTest { .sort(IssueQuery.SORT_BY_ASSIGNEE) .pageSize(10) .pageIndex(2) - .requiredRole(UserRole.CODEVIEWER) + .requiredRole(UserRole.USER) .build(); assertThat(query.issueKeys()).containsOnly("ABCDE"); assertThat(query.severities()).containsOnly(Severity.BLOCKER); @@ -70,7 +70,7 @@ public class IssueQueryTest { assertThat(query.sort()).isEqualTo(IssueQuery.SORT_BY_ASSIGNEE); assertThat(query.pageSize()).isEqualTo(10); assertThat(query.pageIndex()).isEqualTo(2); - assertThat(query.requiredRole()).isEqualTo(UserRole.CODEVIEWER); + assertThat(query.requiredRole()).isEqualTo(UserRole.USER); } @Test diff --git a/sonar-server/src/main/java/org/sonar/server/issue/PublicRubyIssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/PublicRubyIssueService.java index 2f12f8ce1f9..62e6763bc14 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/PublicRubyIssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/PublicRubyIssueService.java @@ -51,12 +51,20 @@ public class PublicRubyIssueService implements RubyIssueService { this.finder = f; } + /** + * Requires the role {@link org.sonar.api.web.UserRole#USER} + */ + @Override public IssueQueryResult find(String issueKey) { - return finder.find(IssueQuery.builder().issueKeys(Arrays.asList(issueKey)).build()); + return finder.find( + IssueQuery.builder() + .issueKeys(Arrays.asList(issueKey)) + .requiredRole(UserRole.USER) + .build()); } /** - * Requires the role {@link org.sonar.api.web.UserRole#CODEVIEWER} + * Requires the role {@link org.sonar.api.web.UserRole#USER} */ @Override public IssueQueryResult find(Map params) { @@ -64,25 +72,25 @@ public class PublicRubyIssueService implements RubyIssueService { } static IssueQuery toQuery(Map props) { - IssueQuery.Builder builder = IssueQuery.builder(); - builder.requiredRole(UserRole.CODEVIEWER); - builder.issueKeys(RubyUtils.toStrings(props.get("issues"))); - builder.severities(RubyUtils.toStrings(props.get("severities"))); - builder.statuses(RubyUtils.toStrings(props.get("statuses"))); - builder.resolutions(RubyUtils.toStrings(props.get("resolutions"))); - builder.resolved(RubyUtils.toBoolean(props.get("resolved"))); - builder.components(RubyUtils.toStrings(props.get("components"))); - builder.componentRoots(RubyUtils.toStrings(props.get("componentRoots"))); - builder.rules(toRules(props.get("rules"))); - builder.actionPlans(RubyUtils.toStrings(props.get("actionPlans"))); - builder.reporters(RubyUtils.toStrings(props.get("reporters"))); - builder.assignees(RubyUtils.toStrings(props.get("assignees"))); - builder.assigned(RubyUtils.toBoolean(props.get("assigned"))); - builder.planned(RubyUtils.toBoolean(props.get("planned"))); - builder.createdAfter(RubyUtils.toDate(props.get("createdAfter"))); - builder.createdBefore(RubyUtils.toDate(props.get("createdBefore"))); - builder.pageSize(RubyUtils.toInteger(props.get("pageSize"))); - builder.pageIndex(RubyUtils.toInteger(props.get("pageIndex"))); + IssueQuery.Builder builder = IssueQuery.builder() + .requiredRole(UserRole.USER) + .issueKeys(RubyUtils.toStrings(props.get("issues"))) + .severities(RubyUtils.toStrings(props.get("severities"))) + .statuses(RubyUtils.toStrings(props.get("statuses"))) + .resolutions(RubyUtils.toStrings(props.get("resolutions"))) + .resolved(RubyUtils.toBoolean(props.get("resolved"))) + .components(RubyUtils.toStrings(props.get("components"))) + .componentRoots(RubyUtils.toStrings(props.get("componentRoots"))) + .rules(toRules(props.get("rules"))) + .actionPlans(RubyUtils.toStrings(props.get("actionPlans"))) + .reporters(RubyUtils.toStrings(props.get("reporters"))) + .assignees(RubyUtils.toStrings(props.get("assignees"))) + .assigned(RubyUtils.toBoolean(props.get("assigned"))) + .planned(RubyUtils.toBoolean(props.get("planned"))) + .createdAfter(RubyUtils.toDate(props.get("createdAfter"))) + .createdBefore(RubyUtils.toDate(props.get("createdBefore"))) + .pageSize(RubyUtils.toInteger(props.get("pageSize"))) + .pageIndex(RubyUtils.toInteger(props.get("pageIndex"))); String sort = (String) props.get("sort"); if (sort != null) { builder.sort(sort); diff --git a/sonar-server/src/test/java/org/sonar/server/issue/PublicRubyIssueServiceTest.java b/sonar-server/src/test/java/org/sonar/server/issue/PublicRubyIssueServiceTest.java index 8552facf9bb..3a99e736e43 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/PublicRubyIssueServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/PublicRubyIssueServiceTest.java @@ -44,13 +44,25 @@ public class PublicRubyIssueServiceTest { PublicRubyIssueService facade = new PublicRubyIssueService(finder); @Test - public void find() throws Exception { + public void find_by_issue_keys() throws Exception { + facade.find("ABCDE"); + verify(finder).find(argThat(new ArgumentMatcher() { + @Override + public boolean matches(Object o) { + IssueQuery query = (IssueQuery) o; + return query.issueKeys().contains("ABCDE") && UserRole.USER.equals(query.requiredRole()); + } + })); + } + + @Test + public void find_by_params() throws Exception { facade.find(ImmutableMap.of("issues", Lists.newArrayList("ABCDE"))); verify(finder).find(argThat(new ArgumentMatcher() { @Override public boolean matches(Object o) { IssueQuery query = (IssueQuery) o; - return query.issueKeys().contains("ABCDE") && UserRole.CODEVIEWER.equals(query.requiredRole()); + return query.issueKeys().contains("ABCDE") && UserRole.USER.equals(query.requiredRole()); } })); } -- 2.39.5