From: Jean-Baptiste Lievremont Date: Thu, 19 Feb 2015 09:00:08 +0000 (+0100) Subject: SONAR-5861 Ability to hide issue comments X-Git-Tag: 5.1-RC1~188 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F105%2Fhead;p=sonarqube.git SONAR-5861 Ability to hide issue comments --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQuery.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQuery.java index 219b157c277..4360c7a0fb6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQuery.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueQuery.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterParameters.java b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterParameters.java index bb2533c9b39..b63bce55ead 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterParameters.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterParameters.java @@ -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 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 ALL_WITHOUT_PAGINATION = newArrayList(Iterables.filter(ALL, new Predicate() { @Override diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java index 10677ed8977..52572d1529c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java @@ -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 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 comments = dbClient.issueChangeDao().selectCommentsByIssues(session, issueKeys); + for (DefaultIssueComment issueComment : comments) { + userLogins.add(issueComment.userLogin()); + commentsByIssues.put(issueComment.issueKey(), issueComment); + } } usersByLogin = getUsersByLogin(userLogins); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java index d1bf870bfdc..2c00d1216ce 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java @@ -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 index 00000000000..a08a3827399 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_comment_hidden.json @@ -0,0 +1,7 @@ +{ + "issues": [ + { + "key": "82fd47d4-b650-4037-80bc-7b112bd4eac2" + } + ] +}