]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13117 Fix SSF-103
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 21 Feb 2020 16:47:01 +0000 (17:47 +0100)
committersonartech <sonartech@sonarsource.com>
Mon, 2 Mar 2020 08:01:24 +0000 (09:01 +0100)
server/sonar-server/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/IssueSnippetsActionTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/sources/IssueSnippetsRequest.java [new file with mode: 0644]
sonar-ws/src/main/java/org/sonarqube/ws/client/sources/SourcesService.java

index 80b5114dba837505969277db4a463263f31ac60d..cf05fd44ac953f65a26ba4ca639108ed7277330e 100644 (file)
@@ -89,7 +89,7 @@ public class IssueSnippetsAction implements SourcesWsAction {
         .orElseThrow(() -> new NotFoundException(format("Issue with key '%s' does not exist", issueKey)));
       ComponentDto project = dbClient.componentDao().selectByUuid(dbSession, issueDto.getProjectUuid())
         .orElseThrow(() -> new NotFoundException(format("Project with uuid '%s' does not exist", issueDto.getProjectUuid())));
-      userSession.checkComponentPermission(UserRole.USER, project);
+      userSession.checkComponentPermission(UserRole.CODEVIEWER, project);
 
       DbIssues.Locations locations = issueDto.parseLocations();
       String componentUuid = issueDto.getComponentUuid();
index 742cce0823d952a21efe28bdd3ae80d77524098f..2058b0d3f6725f9271b5c0b4b6da03eea96bb8c8 100644 (file)
@@ -59,6 +59,7 @@ import static org.sonar.api.measures.CoreMetrics.LINES_KEY;
 import static org.sonar.api.measures.CoreMetrics.TECHNICAL_DEBT_KEY;
 import static org.sonar.api.measures.CoreMetrics.TESTS_KEY;
 import static org.sonar.api.measures.CoreMetrics.VIOLATIONS_KEY;
+import static org.sonar.api.web.UserRole.CODEVIEWER;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 
@@ -97,7 +98,7 @@ public class IssueSnippetsActionTest {
     ComponentDto file = insertFile(project, "file");
     DbFileSources.Data fileSources = FileSourceTesting.newFakeData(10).build();
     fileSourceTester.insertFileSource(file, 10, dto -> dto.setSourceData(fileSources));
-    userSession.logIn().addProjectPermission(USER, project, file);
+    userSession.logIn().addProjectPermission(CODEVIEWER, project, file);
 
     String issueKey = insertIssue(file, newLocation(file.uuid(), 5, 5));
 
@@ -124,7 +125,7 @@ public class IssueSnippetsActionTest {
 
     DbFileSources.Data fileSources = FileSourceTesting.newFakeData(10).build();
     fileSourceTester.insertFileSource(file, 10, dto -> dto.setSourceData(fileSources));
-    userSession.logIn().addProjectPermission(USER, project, file);
+    userSession.logIn().addProjectPermission(CODEVIEWER, project, file);
 
     String issueKey = insertIssue(file, newLocation(file.uuid(), 5, 5));
 
@@ -139,7 +140,7 @@ public class IssueSnippetsActionTest {
 
     DbFileSources.Data fileSources = FileSourceTesting.newFakeData(10).build();
     fileSourceTester.insertFileSource(file, 10, dto -> dto.setSourceData(fileSources));
-    userSession.logIn().addProjectPermission(USER, project, file);
+    userSession.logIn().addProjectPermission(CODEVIEWER, project, file);
 
     String issueKey = insertIssue(file, newLocation(file2.uuid(), 5, 5));
 
@@ -150,7 +151,7 @@ public class IssueSnippetsActionTest {
   @Test
   public void no_code_to_display() {
     ComponentDto file = insertFile(project, "file");
-    userSession.logIn().addProjectPermission(USER, project, file);
+    userSession.logIn().addProjectPermission(CODEVIEWER, project, file);
 
     String issueKey = insertIssue(file, newLocation(file.uuid(), 5, 5));
 
@@ -161,6 +162,7 @@ public class IssueSnippetsActionTest {
   @Test
   public void fail_if_no_project_permission() {
     ComponentDto file = insertFile(project, "file");
+    userSession.logIn().addProjectPermission(USER, project, file);
     String issueKey = insertIssue(file, newLocation(file.uuid(), 5, 5));
 
     expectedException.expect(ForbiddenException.class);
@@ -171,7 +173,7 @@ public class IssueSnippetsActionTest {
   public void fail_if_issue_not_found() {
     ComponentDto file = insertFile(project, "file");
     insertIssue(file, newLocation(file.uuid(), 5, 5));
-    userSession.logIn().addProjectPermission(USER, project, file);
+    userSession.logIn().addProjectPermission(CODEVIEWER, project, file);
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("Issue with key 'invalid' does not exist");
@@ -180,8 +182,12 @@ public class IssueSnippetsActionTest {
 
   @Test
   public void fail_if_parameter_missing() {
+    ComponentDto file = insertFile(project, "file");
+    userSession.logIn().addProjectPermission(CODEVIEWER, project, file);
+
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The 'issueKey' parameter is missing");
+
     actionTester.newRequest().execute();
   }
 
@@ -194,7 +200,7 @@ public class IssueSnippetsActionTest {
     fileSourceTester.insertFileSource(file1, 10, dto -> dto.setSourceData(fileSources));
     fileSourceTester.insertFileSource(file2, 10, dto -> dto.setSourceData(fileSources));
 
-    userSession.logIn().addProjectPermission(USER, project, file1, file2);
+    userSession.logIn().addProjectPermission(CODEVIEWER, project, file1, file2);
 
     String issueKey1 = insertIssue(file1, newLocation(file1.uuid(), 5, 5),
       newLocation(file1.uuid(), 9, 9), newLocation(file2.uuid(), 1, 5));
@@ -213,7 +219,7 @@ public class IssueSnippetsActionTest {
     DbFileSources.Data fileSources = FileSourceTesting.newFakeData(20).build();
     fileSourceTester.insertFileSource(file1, 20, dto -> dto.setSourceData(fileSources));
 
-    userSession.logIn().addProjectPermission(USER, project, file1);
+    userSession.logIn().addProjectPermission(CODEVIEWER, project, file1);
 
     // these two locations should get connected, making a single range 3-14
     String issueKey1 = insertIssue(file1, newLocation(file1.uuid(), 5, 5),
@@ -236,7 +242,7 @@ public class IssueSnippetsActionTest {
     fileSourceTester.insertFileSource(file2, 10, dto -> dto.setSourceData(fileSources));
 
     userSession.logIn()
-      .addProjectPermission(USER, project, file1, file2)
+      .addProjectPermission(CODEVIEWER, project, file1, file2)
       .addMembership(organization);
 
     String issueKey1 = insertIssue(file1, newLocation(file1.uuid(), 5, 5),
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/sources/IssueSnippetsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/sources/IssueSnippetsRequest.java
new file mode 100644 (file)
index 0000000..a128524
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonarqube.ws.client.sources;
+
+import javax.annotation.Generated;
+
+/**
+ * This is part of the internal API.
+ * This is a POST request.
+ * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/sources/issue_snippets">Further information about this action online (including a response example)</a>
+ * @since 7.8
+ */
+@Generated("sonar-ws-generator")
+public class IssueSnippetsRequest {
+
+  private String issueKey;
+
+  /**
+   * This is a mandatory parameter.
+   * Example value: "AU-Tpxb--iU5OvuD2FLy"
+   */
+  public IssueSnippetsRequest setIssueKey(String issueKey) {
+    this.issueKey = issueKey;
+    return this;
+  }
+
+  public String getIssueKey() {
+    return issueKey;
+  }
+}
index 41363d1c6357c60fee5a92d949fdc52ba52c4639..0cfa2276144aae820714bb3f8d3947408e5a4f2a 100644 (file)
@@ -69,6 +69,21 @@ public class SourcesService extends BaseService {
       ).content();
   }
 
+  /**
+   *
+   * This is part of the internal API.
+   * This is a GET request.
+   * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/sources/issue_snippets">Further information about this action online (including a response example)</a>
+   * @since 5.0
+   */
+  public String issueSnippets(IssueSnippetsRequest request) {
+    return call(
+      new GetRequest(path("issue_snippets"))
+        .setParam("issueKey", request.getIssueKey())
+        .setMediaType(MediaTypes.JSON)
+    ).content();
+  }
+
   /**
    *
    * This is part of the internal API.