]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-23142 Fix SSF branch-9.9
authorAnita Stanisz <106669481+anita-stanisz-sonarsource@users.noreply.github.com>
Fri, 11 Oct 2024 15:03:44 +0000 (17:03 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 15 Oct 2024 20:03:04 +0000 (20:03 +0000)
28 files changed:
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AddCommentAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/AssignAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DeleteCommentAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/EditCommentAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/OperationResponseWriter.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTagsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/LinesJsonWriter.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/ScmAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/DeleteCommentActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/EditCommentActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchResponseFormatFormatOperationTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java
server/sonar-webserver-webapi/src/test/resources/org/sonar/server/source/ws/LinesActionTest/hide_scmAuthors.json
server/sonar-webserver-webapi/src/test/resources/org/sonar/server/source/ws/ScmActionTest/hide_author.json [new file with mode: 0644]

index 696d8bc08ab35d7369ea1d843249df297b28a26a..d746c0dbec08a8d69beaadc70058ac3ff1fde23c 100644 (file)
@@ -100,7 +100,7 @@ public class AddCommentAction implements IssuesWsAction {
       DefaultIssue defaultIssue = issueDto.toDefaultIssue();
       issueFieldsSetter.addComment(defaultIssue, wsRequest.getText(), context);
       SearchResponseData preloadedSearchResponseData = issueUpdater.saveIssueAndPreloadSearchResponseData(dbSession, defaultIssue, context);
-      responseWriter.write(defaultIssue.key(), preloadedSearchResponseData, request, response);
+      responseWriter.write(defaultIssue.key(), preloadedSearchResponseData, request, response, true);
     }
   }
 
index d3b87fb0c9a328e914478efb8d746ed7ebbb3741..619b94aac88198c2b497f50b60844d91ac8fabae 100644 (file)
@@ -97,7 +97,7 @@ public class AssignAction implements IssuesWsAction {
     String assignee = getAssignee(request);
     String key = request.mandatoryParam(PARAM_ISSUE);
     SearchResponseData preloadedResponseData = assign(key, assignee);
-    responseWriter.write(key, preloadedResponseData, request, response);
+    responseWriter.write(key, preloadedResponseData, request, response, true);
   }
 
   private SearchResponseData assign(String issueKey, @Nullable String login) {
index fe24e8f00e921ae92f0d895f37a583cc1f079a43..592bfcb1d770b56b0ad5242b6dbff93ba569e8cf 100644 (file)
@@ -83,7 +83,7 @@ public class DeleteCommentAction implements IssuesWsAction {
       CommentData commentData = loadCommentData(dbSession, request);
       deleteComment(dbSession, commentData);
       IssueDto issueDto = commentData.getIssueDto();
-      responseWriter.write(issueDto.getKey(), new SearchResponseData(issueDto), request, response);
+      responseWriter.write(issueDto.getKey(), new SearchResponseData(issueDto), request, response, true);
     }
   }
 
index f0ef92a11da7f21db669d2ddf3e0325c8c526499..bf3ceb5f714e0e54f1206738af2f85d198ceeb7e 100644 (file)
@@ -109,7 +109,7 @@ public class DoTransitionAction implements IssuesWsAction {
     try (DbSession dbSession = dbClient.openSession(false)) {
       IssueDto issueDto = issueFinder.getByKey(dbSession, issue);
       SearchResponseData preloadedSearchResponseData = doTransition(dbSession, issueDto, request.mandatoryParam(PARAM_TRANSITION));
-      responseWriter.write(issue, preloadedSearchResponseData, request, response);
+      responseWriter.write(issue, preloadedSearchResponseData, request, response, true);
     }
   }
 
index 73958a4f44609f86edb4822cd4475a7904419f19..521fc143ae7a3dfd30d33abc170286923a4ed089 100644 (file)
@@ -93,7 +93,7 @@ public class EditCommentAction implements IssuesWsAction {
       CommentData commentData = loadCommentData(dbSession, toWsRequest(request));
       updateComment(dbSession, commentData);
       IssueDto issueDto = commentData.getIssueDto();
-      responseWriter.write(issueDto.getKey(), new SearchResponseData(issueDto), request, response);
+      responseWriter.write(issueDto.getKey(), new SearchResponseData(issueDto), request, response, true);
     }
   }
 
index 427beca3c6fa85d95d64da0749041f8fa311cbf9..717ec46168748e1c3a3a58844c606b9dc7ecc04a 100644 (file)
@@ -37,11 +37,11 @@ public class OperationResponseWriter {
     this.format = format;
   }
 
-  public void write(String issueKey, SearchResponseData preloadedResponseData, Request request, Response response) {
+  public void write(String issueKey, SearchResponseData preloadedResponseData, Request request, Response response, boolean showAuthor) {
     SearchResponseLoader.Collector collector = new SearchResponseLoader.Collector(singletonList(issueKey));
     SearchResponseData data = loader.load(preloadedResponseData, collector, ALL_ADDITIONAL_FIELDS,null);
 
-    Issues.Operation responseBody = format.formatOperation(data);
+    Issues.Operation responseBody = format.formatOperation(data, showAuthor);
 
     WsUtils.writeProtobuf(responseBody, request, response);
   }
index a1cd90901f4cca3ed61cd91e368d5cc196c96633..e0c16728977d2b7bc9b5d978a522e7fdf60d9ad2 100644 (file)
@@ -451,14 +451,14 @@ public class SearchAction implements IssuesWsAction {
 
     // FIXME allow long in Paging
     Paging paging = forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) getTotalHits(result).value);
-    return searchResponseFormat.formatSearch(additionalFields, data, paging, facets);
+    return searchResponseFormat.formatSearch(additionalFields, data, paging, facets, userSession.isLoggedIn());
   }
 
   private static TotalHits getTotalHits(SearchResponse response) {
     return ofNullable(response.getHits().getTotalHits()).orElseThrow(() -> new IllegalStateException("Could not get total hits of search results"));
   }
 
-  private static SearchOptions createSearchOptionsFromRequest(SearchRequest request) {
+  private SearchOptions createSearchOptionsFromRequest(SearchRequest request) {
     SearchOptions options = new SearchOptions();
     options.setPage(request.getPage(), request.getPageSize());
 
@@ -468,7 +468,11 @@ public class SearchAction implements IssuesWsAction {
       return options;
     }
 
-    options.addFacets(facets);
+    List<String> requestedFacets = new ArrayList<>(facets);
+    if (!userSession.isLoggedIn()) {
+      requestedFacets.remove(PARAM_AUTHOR);
+    }
+    options.addFacets(requestedFacets);
     return options;
   }
 
index 38ab2365ef3b2fbceec491a26d455b85bffd5092..06e35c4d5fd4df790fa488031b216ab512503d95 100644 (file)
@@ -90,19 +90,21 @@ public class SearchResponseFormat {
   private final TextRangeResponseFormatter textRangeFormatter;
   private final UserResponseFormatter userFormatter;
 
-  public SearchResponseFormat(Durations durations, Languages languages, TextRangeResponseFormatter textRangeFormatter, UserResponseFormatter userFormatter) {
+  public SearchResponseFormat(Durations durations, Languages languages, TextRangeResponseFormatter textRangeFormatter,
+    UserResponseFormatter userFormatter) {
     this.durations = durations;
     this.languages = languages;
     this.textRangeFormatter = textRangeFormatter;
     this.userFormatter = userFormatter;
   }
 
-  SearchWsResponse formatSearch(Set<SearchAdditionalField> fields, SearchResponseData data, Paging paging, Facets facets) {
+  SearchWsResponse formatSearch(Set<SearchAdditionalField> fields, SearchResponseData data, Paging paging, Facets facets,
+    boolean showAuthor) {
     SearchWsResponse.Builder response = SearchWsResponse.newBuilder();
 
     formatPaging(paging, response);
     ofNullable(data.getEffortTotal()).ifPresent(response::setEffortTotal);
-    response.addAllIssues(createIssues(fields, data));
+    response.addAllIssues(createIssues(fields, data, showAuthor));
     response.addAllComponents(formatComponents(data));
     formatFacets(data, facets, response);
     if (fields.contains(SearchAdditionalField.RULES)) {
@@ -117,12 +119,12 @@ public class SearchResponseFormat {
     return response.build();
   }
 
-  Operation formatOperation(SearchResponseData data) {
+  Operation formatOperation(SearchResponseData data, boolean showAuthor) {
     Operation.Builder response = Operation.newBuilder();
 
     if (data.getIssues().size() == 1) {
       IssueDto dto = data.getIssues().get(0);
-      response.setIssue(createIssue(ALL_ADDITIONAL_FIELDS, data, dto));
+      response.setIssue(createIssue(ALL_ADDITIONAL_FIELDS, data, dto, showAuthor));
     }
     response.addAllComponents(formatComponents(data));
     response.addAllRules(formatRules(data).getRulesList());
@@ -144,20 +146,20 @@ public class SearchResponseFormat {
       .setTotal(paging.total());
   }
 
-  private List<Issues.Issue> createIssues(Collection<SearchAdditionalField> fields, SearchResponseData data) {
+  private List<Issues.Issue> createIssues(Collection<SearchAdditionalField> fields, SearchResponseData data, boolean showAuthor) {
     return data.getIssues().stream()
-      .map(dto -> createIssue(fields, data, dto))
+      .map(dto -> createIssue(fields, data, dto, showAuthor))
       .toList();
   }
 
-  private Issue createIssue(Collection<SearchAdditionalField> fields, SearchResponseData data, IssueDto dto) {
+  private Issue createIssue(Collection<SearchAdditionalField> fields, SearchResponseData data, IssueDto dto, boolean showAuthor) {
     Issue.Builder issueBuilder = Issue.newBuilder();
-    addMandatoryFieldsToIssueBuilder(issueBuilder, dto, data);
+    addMandatoryFieldsToIssueBuilder(issueBuilder, dto, data, showAuthor);
     addAdditionalFieldsToIssueBuilder(fields, data, dto, issueBuilder);
     return issueBuilder.build();
   }
 
-  private void addMandatoryFieldsToIssueBuilder(Issue.Builder issueBuilder, IssueDto dto, SearchResponseData data) {
+  private void addMandatoryFieldsToIssueBuilder(Issue.Builder issueBuilder, IssueDto dto, SearchResponseData data, boolean showAuthor) {
     issueBuilder.setKey(dto.getKey());
     issueBuilder.setType(Common.RuleType.forNumber(dto.getType()));
 
@@ -176,6 +178,7 @@ public class SearchResponseFormat {
       issueBuilder.setSeverity(Common.Severity.valueOf(dto.getSeverity()));
     }
     ofNullable(data.getUserByUuid(dto.getAssigneeUuid())).ifPresent(assignee -> issueBuilder.setAssignee(assignee.getLogin()));
+
     ofNullable(emptyToNull(dto.getResolution())).ifPresent(issueBuilder::setResolution);
     issueBuilder.setStatus(dto.getStatus());
     issueBuilder.setMessage(nullToEmpty(dto.getMessage()));
@@ -191,7 +194,9 @@ public class SearchResponseFormat {
     ofNullable(emptyToNull(dto.getChecksum())).ifPresent(issueBuilder::setHash);
     completeIssueLocations(dto, issueBuilder, data);
 
-    issueBuilder.setAuthor(nullToEmpty(dto.getAuthorLogin()));
+    if (showAuthor) {
+      issueBuilder.setAuthor(nullToEmpty(dto.getAuthorLogin()));
+    }
     ofNullable(dto.getIssueCreationDate()).map(DateUtils::formatDateTime).ifPresent(issueBuilder::setCreationDate);
     ofNullable(dto.getIssueUpdateDate()).map(DateUtils::formatDateTime).ifPresent(issueBuilder::setUpdateDate);
     ofNullable(dto.getIssueCloseDate()).map(DateUtils::formatDateTime).ifPresent(issueBuilder::setCloseDate);
@@ -202,7 +207,8 @@ public class SearchResponseFormat {
     issueBuilder.setScope(UNIT_TEST_FILE.equals(component.qualifier()) ? IssueScope.TEST.name() : IssueScope.MAIN.name());
   }
 
-  private static void addAdditionalFieldsToIssueBuilder(Collection<SearchAdditionalField> fields, SearchResponseData data, IssueDto dto, Issue.Builder issueBuilder) {
+  private static void addAdditionalFieldsToIssueBuilder(Collection<SearchAdditionalField> fields, SearchResponseData data, IssueDto dto,
+    Issue.Builder issueBuilder) {
     if (fields.contains(ACTIONS)) {
       issueBuilder.setActions(createIssueActions(data, dto));
     }
index d5b27b936288192cb3a660d751d5b9aef614cd67..e9e9430fa5e692031d488ab9ab5a02e7e6f30285 100644 (file)
@@ -103,7 +103,7 @@ public class SetSeverityAction implements IssuesWsAction {
     String severity = request.mandatoryParam(PARAM_SEVERITY);
     try (DbSession session = dbClient.openSession(false)) {
       SearchResponseData preloadedSearchResponseData = setType(session, issueKey, severity);
-      responseWriter.write(issueKey, preloadedSearchResponseData, request, response);
+      responseWriter.write(issueKey, preloadedSearchResponseData, request, response, true);
     }
   }
 
index 355e337fdf33c2608a4161e8d681f5e7448de60d..c9735eab1f7f5715f1b1e1a2482408b2a51085fa 100644 (file)
@@ -95,7 +95,7 @@ public class SetTagsAction implements IssuesWsAction {
     String key = request.mandatoryParam(PARAM_ISSUE);
     List<String> tags = MoreObjects.firstNonNull(request.paramAsStrings(PARAM_TAGS), Collections.emptyList());
     SearchResponseData preloadedSearchResponseData = setTags(key, tags);
-    responseWriter.write(key, preloadedSearchResponseData, request, response);
+    responseWriter.write(key, preloadedSearchResponseData, request, response, true);
   }
 
   private SearchResponseData setTags(String issueKey, List<String> tags) {
index 9231fa66d8d56256dc8b3bdd37be97c480c562f9..9cdb0d665316547348c40329fc522a590284bc69 100644 (file)
@@ -107,7 +107,7 @@ public class SetTypeAction implements IssuesWsAction {
     RuleType ruleType = RuleType.valueOf(request.mandatoryParam(PARAM_TYPE));
     try (DbSession session = dbClient.openSession(false)) {
       SearchResponseData preloadedSearchResponseData = setType(session, issueKey, ruleType);
-      responseWriter.write(issueKey, preloadedSearchResponseData, request, response);
+      responseWriter.write(issueKey, preloadedSearchResponseData, request, response, true);
     }
   }
 
index 7d8a89e881240e48f4358bff7ea6709fa994b0e1..16716a9824f3d0c5bc510eae6a9e8491b5beeede 100644 (file)
@@ -145,7 +145,7 @@ public class IssueSnippetsAction implements SourcesWsAction {
     componentViewerJsonWriter.writeComponentWithoutFav(writer, fileDto, dbSession, branch, pullRequest);
     componentViewerJsonWriter.writeMeasures(writer, fileDto, dbSession);
     writer.endObject();
-    linesJsonWriter.writeSource(lineSources, writer, periodDateSupplier);
+    linesJsonWriter.writeSource(lineSources, writer, periodDateSupplier, userSession.isLoggedIn());
 
     writer.endObject();
   }
index 50fa3e9114760ac4238609657f1598fe7080c8c5..9988fba5d75e111f9951a5b22e6121799e518abb 100644 (file)
@@ -150,7 +150,7 @@ public class LinesAction implements SourcesWsAction {
         "No source found for file '%s' (uuid: %s)", file.getKey(), file.uuid());
       try (JsonWriter json = response.newJsonWriter()) {
         json.beginObject();
-        linesJsonWriter.writeSource(lines, json, periodDateSupplier);
+        linesJsonWriter.writeSource(lines, json, periodDateSupplier, userSession.isLoggedIn());
         json.endObject();
       }
     }
index 34bacaed64ed1c46ff58a48d602033df1b284730..b23bbd65134b7359c99c1ba4302ee979c50660a8 100644 (file)
@@ -34,7 +34,8 @@ public class LinesJsonWriter {
     this.htmlSourceDecorator = htmlSourceDecorator;
   }
 
-  public void writeSource(Iterable<DbFileSources.Line> lines, JsonWriter json, Supplier<Optional<Long>> periodDateSupplier) {
+  public void writeSource(Iterable<DbFileSources.Line> lines, JsonWriter json, Supplier<Optional<Long>> periodDateSupplier,
+    boolean showAuthor) {
     Long periodDate = null;
 
     json.name("sources").beginArray();
@@ -43,7 +44,9 @@ public class LinesJsonWriter {
         .prop("line", line.getLine())
         .prop("code", htmlSourceDecorator.getDecoratedSourceAsHtml(line.getSource(), line.getHighlighting(), line.getSymbols()))
         .prop("scmRevision", line.getScmRevision());
-      json.prop("scmAuthor", line.getScmAuthor());
+      if (showAuthor) {
+        json.prop("scmAuthor", line.getScmAuthor());
+      }
       if (line.hasScmDate()) {
         json.prop("scmDate", DateUtils.formatDateTime(new Date(line.getScmDate())));
       }
index 894cfa39283729eecc303df69ef5ff13721b6a8a..5d176afa0c9064b0a4dfd0720180072e130a76f6 100644 (file)
@@ -104,7 +104,8 @@ public class ScmAction implements SourcesWsAction {
     try (DbSession dbSession = dbClient.openSession(false)) {
       ComponentDto file = componentFinder.getByKey(dbSession, fileKey);
       userSession.checkComponentPermission(UserRole.CODEVIEWER, file);
-      Iterable<DbFileSources.Line> sourceLines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "File '%s' has no sources", fileKey);
+      Iterable<DbFileSources.Line> sourceLines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "File " +
+        "'%s' has no sources", fileKey);
       try (JsonWriter json = response.newJsonWriter()) {
         json.beginObject();
         writeSource(sourceLines, commitsByLine, json);
@@ -113,7 +114,7 @@ public class ScmAction implements SourcesWsAction {
     }
   }
 
-  private static void writeSource(Iterable<DbFileSources.Line> lines, boolean showCommitsByLine, JsonWriter json) {
+  private void writeSource(Iterable<DbFileSources.Line> lines, boolean showCommitsByLine, JsonWriter json) {
     json.name("scm").beginArray();
 
     DbFileSources.Line previousLine = null;
@@ -121,8 +122,8 @@ public class ScmAction implements SourcesWsAction {
     for (DbFileSources.Line lineDoc : lines) {
       if (hasScm(lineDoc) && (!started || showCommitsByLine || !isSameCommit(previousLine, lineDoc))) {
         json.beginArray()
-          .value(lineDoc.getLine())
-          .value(lineDoc.getScmAuthor());
+          .value(lineDoc.getLine());
+        json.value(userSession.isLoggedIn() ? lineDoc.getScmAuthor() : "");
         json.value(lineDoc.hasScmDate() ? DateUtils.formatDateTime(new Date(lineDoc.getScmDate())) : null);
         json.value(lineDoc.getScmRevision());
         json.endArray();
index e957a923fd8f9989ff7c74a31b950f884f0851d5..1c5047691c9519e242014fd239c2f1ed7c452096 100644 (file)
@@ -113,7 +113,7 @@ public class AddCommentActionTest {
 
     call(issueDto.getKey(), "please fix it");
 
-    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class));
+    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true));
     verifyContentOfPreloadedSearchResponseData(issueDto);
 
     IssueChangeDto issueComment = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbTester.getSession(), singletonList(issueDto.getKey()), TYPE_COMMENT).get(0);
index afc581737b8a0b219ce20be8b7b28a1040bbbd6c..0d51fec237107df286a7fb93bfb38815178bb22e 100644 (file)
@@ -75,7 +75,7 @@ public class DeleteCommentActionTest {
 
     call(commentDto.getKey());
 
-    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class));
+    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true));
     assertThat(dbClient.issueChangeDao().selectCommentByKey(dbTester.getSession(), commentDto.getKey())).isNotPresent();
     verifyContentOfPreloadedSearchResponseData(issueDto);
   }
index 0ae11cebe577f9aa3c8a2348340fb2c728827d2c..00e9899cf5e0b036809cd78711ab7e65c79c2448 100644 (file)
@@ -125,7 +125,7 @@ public class DoTransitionActionTest {
 
     call(issue.getKey(), "confirm");
 
-    verify(responseWriter).write(eq(issue.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class));
+    verify(responseWriter).write(eq(issue.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true));
     verifyContentOfPreloadedSearchResponseData(issue);
     verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any());
     IssueDto issueReloaded = db.getDbClient().issueDao().selectByKey(db.getSession(), issue.getKey()).get();
index 246ef6b6c291cde6254c74d81e9412c2aa30f2d2..f8837ebd40cae1342cea62c59598484dc949898f 100644 (file)
@@ -86,7 +86,7 @@ public class EditCommentActionTest {
 
     call(commentDto.getKey(), "please have a look");
 
-    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class));
+    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true));
 
     verifyContentOfPreloadedSearchResponseData(issueDto);
     IssueChangeDto issueComment = dbClient.issueChangeDao().selectCommentByKey(dbTester.getSession(), commentDto.getKey()).get();
index 6e93803b06e348e282e042119c4140512faa793c..d0f4aeb5e0e13e5ae164138b78abf0c4620322f1 100644 (file)
@@ -916,6 +916,7 @@ public class SearchActionTest {
 
   @Test
   public void search_by_author() {
+    userSession.logIn();
     ComponentDto project = db.components().insertPublicProject();
     ComponentDto file = db.components().insertComponent(newFileDto(project, null));
     RuleDto rule = db.rules().insertIssueRule();
@@ -946,6 +947,27 @@ public class SearchActionTest {
       .isEmpty();
   }
 
+  @Test
+  public void hide_author_if_not_logged_in() {
+    ComponentDto project = db.components().insertPublicProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    RuleDto rule = db.rules().insertIssueRule();
+    db.issues().insertIssue(rule, project, file, i -> i.setAuthorLogin("leia"));
+    db.issues().insertIssue(rule, project, file, i -> i.setAuthorLogin("luke"));
+    db.issues().insertIssue(rule, project, file, i -> i.setAuthorLogin("han, solo"));
+    indexPermissionsAndIssues();
+
+    SearchWsResponse response = ws.newRequest()
+      .setMultiParam("author", asList("leia", "han, solo"))
+      .setParam(FACETS, "author")
+      .executeProtobuf(SearchWsResponse.class);
+
+    assertThat(response.getIssuesList())
+      .extracting(Issue::getAuthor)
+      .containsExactlyInAnyOrder("", "");
+   assertThat(response.getFacets().getFacetsList()).isEmpty();
+  }
+
   @Test
   public void filter_by_test_scope() {
     ComponentDto project = db.components().insertPublicProject("PROJECT_ID", c -> c.setKey("PROJECT_KEY"));
index 5ee116be146652ec329b6ad275f82b9eb6b8b82b..0cabe964963c7e65133c5d443d96cf43b739246b 100644 (file)
@@ -91,7 +91,7 @@ public class SearchResponseFormatFormatOperationTest {
 
   @Test
   public void formatOperation_should_add_components_to_response() {
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getComponentsList()).hasSize(1);
     assertThat(result.getComponentsList().get(0).getKey()).isEqualTo(issueDto.getComponentKey());
@@ -99,7 +99,7 @@ public class SearchResponseFormatFormatOperationTest {
 
   @Test
   public void formatOperation_should_add_rules_to_response() {
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getRulesList()).hasSize(1);
     assertThat(result.getRulesList().get(0).getKey()).isEqualTo(issueDto.getRuleKey().toString());
@@ -107,7 +107,7 @@ public class SearchResponseFormatFormatOperationTest {
 
   @Test
   public void formatOperation_should_add_users_to_response() {
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getUsersList()).hasSize(1);
     assertThat(result.getUsers(0)).isSameAs(user);
@@ -115,7 +115,7 @@ public class SearchResponseFormatFormatOperationTest {
 
   @Test
   public void formatOperation_should_add_issue_to_response() {
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertIssueEqualsIssueDto(result.getIssue(), issueDto);
   }
@@ -145,7 +145,7 @@ public class SearchResponseFormatFormatOperationTest {
   public void formatOperation_should_not_add_issue_when_several_issue() {
     searchResponseData = new SearchResponseData(List.of(createIssue(), createIssue()));
 
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getIssue()).isEqualTo(Issue.getDefaultInstance());
   }
@@ -162,14 +162,14 @@ public class SearchResponseFormatFormatOperationTest {
   public void formatOperation_should_add_branch_on_issue() {
     String branchName = randomAlphanumeric(5);
     searchResponseData = newSearchResponseDataBranch(branchName);
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
     assertThat(result.getIssue().getBranch()).isEqualTo(branchName);
   }
 
   @Test
   public void formatOperation_should_add_pullrequest_on_issue() {
     searchResponseData = newSearchResponseDataPr("pr1");
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
     assertThat(result.getIssue().getPullRequest()).isEqualTo("pr1");
   }
 
@@ -177,7 +177,7 @@ public class SearchResponseFormatFormatOperationTest {
   public void formatOperation_should_add_project_on_issue() {
     issueDto.setProjectUuid(componentDto.uuid());
 
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getIssue().getProject()).isEqualTo(componentDto.getKey());
   }
@@ -188,7 +188,7 @@ public class SearchResponseFormatFormatOperationTest {
     String expected = randomAlphanumeric(5);
     issueDto.setRuleKey(EXTERNAL_RULE_REPO_PREFIX + expected, randomAlphanumeric(5));
 
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getIssue().getExternalRuleEngine()).isEqualTo(expected);
   }
@@ -199,7 +199,7 @@ public class SearchResponseFormatFormatOperationTest {
     issueDto.setEffort(effort);
     String expected = durations.encode(Duration.create(effort));
 
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getIssue().getEffort()).isEqualTo(expected);
     assertThat(result.getIssue().getDebt()).isEqualTo(expected);
@@ -209,7 +209,7 @@ public class SearchResponseFormatFormatOperationTest {
   public void formatOperation_should_add_scope_test_on_issue_when_unit_test_file() {
     componentDto.setQualifier(UNIT_TEST_FILE);
 
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getIssue().getScope()).isEqualTo(TEST.name());
   }
@@ -218,7 +218,7 @@ public class SearchResponseFormatFormatOperationTest {
   public void formatOperation_should_add_scope_main_on_issue_when_not_unit_test_file() {
     componentDto.setQualifier(randomAlphanumeric(5));
 
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getIssue().getScope()).isEqualTo(MAIN.name());
   }
@@ -228,7 +228,7 @@ public class SearchResponseFormatFormatOperationTest {
     Set<String> expectedActions = Set.of("actionA", "actionB");
     searchResponseData.addActions(issueDto.getKey(), expectedActions);
 
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getIssue().getActions().getActionsList()).containsExactlyInAnyOrderElementsOf(expectedActions);
   }
@@ -238,7 +238,7 @@ public class SearchResponseFormatFormatOperationTest {
     Set<String> expectedTransitions = Set.of("transitionone", "transitiontwo");
     searchResponseData.addTransitions(issueDto.getKey(), createFakeTransitions(expectedTransitions));
 
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getIssue().getTransitions().getTransitionsList()).containsExactlyInAnyOrderElementsOf(expectedTransitions);
   }
@@ -254,7 +254,7 @@ public class SearchResponseFormatFormatOperationTest {
     IssueChangeDto issueChangeDto = newIssuechangeDto(issueDto);
     searchResponseData.setComments(List.of(issueChangeDto));
 
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getIssue().getComments().getCommentsList()).hasSize(1).extracting(Common.Comment::getKey).containsExactly(issueChangeDto.getKey());
   }
@@ -263,7 +263,7 @@ public class SearchResponseFormatFormatOperationTest {
   public void formatOperation_should_not_set_severity_for_security_hotspot_issue() {
     issueDto.setType(SECURITY_HOTSPOT);
 
-    Operation result = searchResponseFormat.formatOperation(searchResponseData);
+    Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
 
     assertThat(result.getIssue().hasSeverity()).isFalse();
   }
index 8a54486a0a4e707d45906d0255c67082a16f5f55..97acf03c05c2351e5d00195dc14b1563507472f3 100644 (file)
@@ -108,7 +108,7 @@ public class SetSeverityActionTest {
 
     call(issueDto.getKey(), MINOR);
 
-    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class));
+    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true));
     verifyContentOfPreloadedSearchResponseData(issueDto);
     verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any());
 
index d1cd0c82ab14925b40fecd80620484be015b7a33..d884c27e0d0fcc2135ea98149063c78d91e87b87 100644 (file)
@@ -102,7 +102,7 @@ public class SetTagsActionTest {
 
     call(issueDto.getKey(), "bug", "todo");
 
-    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class));
+    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true));
     verifyContentOfPreloadedSearchResponseData(issueDto);
     IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issueDto.getKey()).get();
     assertThat(issueReloaded.getTags()).containsOnly("bug", "todo");
index a3c07cc38b937ba5998ea0bdaa5512211529726b..b5f5bc22779b5210782abbc962bde7f5e6e6152e 100644 (file)
@@ -122,7 +122,7 @@ public class SetTypeActionTest {
 
     call(issueDto.getKey(), to.name());
 
-    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class));
+    verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true));
     IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issueDto.getKey()).get();
     assertThat(issueReloaded.getType()).isEqualTo(to.getDbConstant());
 
index c41e6df709b719ef8c3faa1676942c9fbed398f8..125199b4b81f1c8c113d0e405eee686388beb0e4 100644 (file)
@@ -48,6 +48,7 @@ import org.sonar.server.ws.WsActionTester;
 
 import static java.lang.String.format;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.mock;
@@ -67,7 +68,8 @@ public class LinesActionTest {
   private final HtmlSourceDecorator htmlSourceDecorator = mock(HtmlSourceDecorator.class);
   private final SourceService sourceService = new SourceService(db.getDbClient(), htmlSourceDecorator);
   private final LinesJsonWriter linesJsonWriter = new LinesJsonWriter(htmlSourceDecorator);
-  private final LinesAction underTest = new LinesAction(TestComponentFinder.from(db), db.getDbClient(), sourceService, linesJsonWriter, userSession);
+  private final LinesAction underTest = new LinesAction(TestComponentFinder.from(db), db.getDbClient(), sourceService, linesJsonWriter,
+    userSession);
   private final WsActionTester tester = new WsActionTester(underTest);
 
   @Before
@@ -354,10 +356,12 @@ public class LinesActionTest {
 
     ComponentDto file = insertFileWithData(data, publicProject);
 
-    tester.newRequest()
+    String response = tester.newRequest()
       .setParam("uuid", file.uuid())
       .execute()
-      .assertJson(getClass(), "hide_scmAuthors.json");
+      .getInput();
+
+    assertThat(response).doesNotContain("isaac@asimov.com");
   }
 
   @Test
index 688a201be8d0a5731fdda2b2fe5fc10f07583eba..abc76d138b6bc7019cf84914c5b5dab58d8e0c4d 100644 (file)
@@ -72,6 +72,7 @@ public class ScmActionTest {
 
   @Test
   public void show_scm() {
+    userSessionRule.logIn();
     userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
@@ -88,8 +89,27 @@ public class ScmActionTest {
       .assertJson(getClass(), "show_scm.json");
   }
 
+  @Test
+  public void hide_author_if_not_logged_in() {
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
+
+    dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
+      .setUuid(Uuids.createFast())
+      .setProjectUuid(PROJECT_UUID)
+      .setFileUuid(FILE_UUID)
+      .setSourceData(DbFileSources.Data.newBuilder().addLines(
+        newSourceLine("julien", "123-456-789", DateUtils.parseDateTime("2015-03-30T12:34:56+0000"), 1)).build()));
+    dbSession.commit();
+
+    tester.newRequest()
+      .setParam("key", FILE_KEY)
+      .execute()
+      .assertJson(getClass(), "hide_author.json");
+  }
+
   @Test
   public void show_scm_from_given_range_lines() {
+    userSessionRule.logIn();
     userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
@@ -114,6 +134,7 @@ public class ScmActionTest {
 
   @Test
   public void not_group_lines_by_commit() {
+    userSessionRule.logIn();
     userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     // lines 1 and 2 are the same commit, but not 3 (different date)
@@ -138,6 +159,7 @@ public class ScmActionTest {
 
   @Test
   public void group_lines_by_commit() {
+    userSessionRule.logIn();
     userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     // lines 1 and 2 are the same commit, but not 3 (different date)
@@ -162,6 +184,7 @@ public class ScmActionTest {
 
   @Test
   public void accept_negative_value_in_from_parameter() {
+    userSessionRule.logIn();
     userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
index 2fd47642208d5719729cf3aa74c85b070d6641f7..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,12 +0,0 @@
-{
-  "sources": [
-    {
-      "line": 1,
-      "code": "\u003cp\u003eSOURCE_1\u003c/p\u003e",
-      "scmRevision": "REVISION_1",
-      "scmDate": "1974-10-03T03:40:00+0100",
-      "duplicated": false,
-      "isNew": false
-    }
-  ]
-}
diff --git a/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/source/ws/ScmActionTest/hide_author.json b/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/source/ws/ScmActionTest/hide_author.json
new file mode 100644 (file)
index 0000000..711dd67
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "scm": [
+    [1, "","2015-03-30T12:34:56+0000", "123-456-789"]
+  ]
+}