]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5861 Ability to hide issue comments 105/head
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 19 Feb 2015 09:00:08 +0000 (10:00 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 19 Feb 2015 10:16:24 +0000 (11:16 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/IssueQuery.java
server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterParameters.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_comment_hidden.json [new file with mode: 0644]

index 219b157c27760da200c52fdbec32d9437e877512..4360c7a0fb63e30520912dfb155598dbe0cb287a 100644 (file)
@@ -79,6 +79,7 @@ public class IssueQuery {
   private final Boolean planned;
   private final Boolean resolved;
   private final Boolean hideRules;
+  private final Boolean hideComments;
   private final Date createdAt;
   private final Date createdAfter;
   private final Date createdBefore;
@@ -114,6 +115,7 @@ public class IssueQuery {
     this.planned = builder.planned;
     this.resolved = builder.resolved;
     this.hideRules = builder.hideRules;
+    this.hideComments = builder.hideComments;
     this.createdAt = builder.createdAt;
     this.createdAfter = builder.createdAfter;
     this.createdBefore = builder.createdBefore;
@@ -225,6 +227,14 @@ public class IssueQuery {
     return hideRules;
   }
 
+  /**
+   * @since 5.1
+   */
+  @CheckForNull
+  public Boolean hideComments() {
+    return hideComments;
+  }
+
   @CheckForNull
   public Date createdAfter() {
     return createdAfter == null ? null : new Date(createdAfter.getTime());
@@ -301,6 +311,7 @@ public class IssueQuery {
     private Boolean planned = null;
     private Boolean resolved = null;
     private Boolean hideRules = false;
+    private Boolean hideComments = false;
     private Date createdAt;
     private Date createdAfter;
     private Date createdBefore;
@@ -452,6 +463,18 @@ public class IssueQuery {
       return this;
     }
 
+    /**
+     * If true, comments will not be loaded
+     * If false, comments will be loaded
+     *
+     * @since 5.1
+     *
+     */
+    public Builder hideComments(@Nullable Boolean b) {
+      this.hideComments = b;
+      return this;
+    }
+
     public Builder createdAt(@Nullable Date d) {
       this.createdAt = d == null ? null : new Date(d.getTime());
       return this;
index bb2533c9b39eb45dcb92bbda344e500125b1984f..b63bce55ead4888c0bea9161c115849c70793c71 100644 (file)
@@ -60,6 +60,7 @@ public class IssueFilterParameters {
   public static final String ASSIGNED = "assigned";
   public static final String PLANNED = "planned";
   public static final String HIDE_RULES = "hideRules";
+  public static final String HIDE_COMMENTS = "hideComments";
   public static final String CREATED_AFTER = "createdAfter";
   public static final String CREATED_AT = "createdAt";
   public static final String CREATED_BEFORE = "createdBefore";
@@ -71,7 +72,7 @@ public class IssueFilterParameters {
 
   public static final List<String> ALL = ImmutableList.of(ISSUES, SEVERITIES, STATUSES, RESOLUTIONS, RESOLVED, COMPONENTS, COMPONENT_ROOTS, RULES, ACTION_PLANS, REPORTERS, TAGS,
     ASSIGNEES, LANGUAGES, ASSIGNED, PLANNED, HIDE_RULES, CREATED_AT, CREATED_AFTER, CREATED_BEFORE, PAGE_SIZE, PAGE_INDEX, SORT, ASC, COMPONENT_UUIDS, COMPONENT_ROOT_UUIDS,
-    PROJECTS, PROJECT_UUIDS, IGNORE_PAGING, PROJECT_KEYS, COMPONENT_KEYS, MODULE_UUIDS, DIRECTORIES, FILE_UUIDS, AUTHORS);
+    PROJECTS, PROJECT_UUIDS, IGNORE_PAGING, PROJECT_KEYS, COMPONENT_KEYS, MODULE_UUIDS, DIRECTORIES, FILE_UUIDS, AUTHORS, HIDE_COMMENTS);
 
   public static final List<String> ALL_WITHOUT_PAGINATION = newArrayList(Iterables.filter(ALL, new Predicate<String>() {
     @Override
index 10677ed897702c205fe128d243e83b8efbfd492b..52572d1529c8040d219de70058726e9a8c6d4335 100644 (file)
@@ -155,6 +155,10 @@ public class SearchAction implements BaseIssuesWsAction {
       .setDescription("To not return rules")
       .setDefaultValue(false)
       .setBooleanPossibleValues();
+    action.createParam(IssueFilterParameters.HIDE_COMMENTS)
+      .setDescription("To not return comments")
+      .setDefaultValue(false)
+      .setBooleanPossibleValues();
     action.createParam(IssueFilterParameters.ACTION_PLANS)
       .setDescription("Comma-separated list of action plan keys (not names)")
       .setExampleValue("3f19de90-1521-4482-a737-a311758ff513");
@@ -322,10 +326,12 @@ public class SearchAction implements BaseIssuesWsAction {
 
     DbSession session = dbClient.openSession(false);
     try {
-      List<DefaultIssueComment> comments = dbClient.issueChangeDao().selectCommentsByIssues(session, issueKeys);
-      for (DefaultIssueComment issueComment : comments) {
-        userLogins.add(issueComment.userLogin());
-        commentsByIssues.put(issueComment.issueKey(), issueComment);
+      if (!BooleanUtils.isTrue(request.paramAsBoolean(IssueFilterParameters.HIDE_COMMENTS))) {
+        List<DefaultIssueComment> comments = dbClient.issueChangeDao().selectCommentsByIssues(session, issueKeys);
+        for (DefaultIssueComment issueComment : comments) {
+          userLogins.add(issueComment.userLogin());
+          commentsByIssues.put(issueComment.issueKey(), issueComment);
+        }
       }
       usersByLogin = getUsersByLogin(userLogins);
 
index d1bf870bfdcf01333bc800c2b0602b6ec8096995..2c00d1216cee925671a17bb8c7f6d9c45505e820 100644 (file)
@@ -88,7 +88,7 @@ public class SearchActionMediumTest {
     assertThat(show.isPost()).isFalse();
     assertThat(show.isInternal()).isFalse();
     assertThat(show.responseExampleAsString()).isNotEmpty();
-    assertThat(show.params()).hasSize(38);
+    assertThat(show.params()).hasSize(39);
   }
 
   @Test
@@ -162,6 +162,41 @@ public class SearchActionMediumTest {
     result.assertJson(this.getClass(), "issue_with_comment.json", false);
   }
 
+  @Test
+  public void issue_with_comment_hidden() throws Exception {
+    db.userDao().insert(session, new UserDto().setLogin("john").setName("John").setEmail("john@email.com"));
+    db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
+
+    ComponentDto project = insertComponent(ComponentTesting.newProjectDto("ABCD").setKey("MyProject"));
+    setDefaultProjectPermission(project);
+    ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, "BCDE").setKey("MyComponent"));
+    IssueDto issue = IssueTesting.newDto(newRule(), file, project)
+      .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
+    db.issueDao().insert(session, issue);
+
+    tester.get(IssueChangeDao.class).insert(session,
+      new IssueChangeDto().setIssueKey(issue.getKey())
+        .setKey("COMMENT-ABCD")
+        .setChangeData("*My comment*")
+        .setChangeType(IssueChangeDto.TYPE_COMMENT)
+        .setUserLogin("john")
+        .setCreatedAt(DateUtils.parseDate("2014-09-09").getTime()));
+    tester.get(IssueChangeDao.class).insert(session,
+      new IssueChangeDto().setIssueKey(issue.getKey())
+        .setKey("COMMENT-ABCE")
+        .setChangeData("Another comment")
+        .setChangeType(IssueChangeDto.TYPE_COMMENT)
+        .setUserLogin("fabrice")
+        .setCreatedAt(DateUtils.parseDate("2014-09-10").getTime()));
+    session.commit();
+    tester.get(IssueIndexer.class).indexAll();
+
+    MockUserSession.set().setLogin("john");
+    WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).setParam(IssueFilterParameters.HIDE_COMMENTS, "true").execute();
+    result.assertJson(this.getClass(), "issue_with_comment_hidden.json", false);
+    assertThat(result.outputAsString()).doesNotContain("fabrice");
+  }
+
   @Test
   public void issue_with_action_plan() throws Exception {
     ComponentDto project = insertComponent(ComponentTesting.newProjectDto("ABCD").setKey("MyProject"));
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_comment_hidden.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_comment_hidden.json
new file mode 100644 (file)
index 0000000..a08a382
--- /dev/null
@@ -0,0 +1,7 @@
+{
+  "issues": [
+    {
+      "key": "82fd47d4-b650-4037-80bc-7b112bd4eac2"
+    }
+  ]
+}