]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12075 remove double negative boolean and a SQL request
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 18 Jun 2019 09:06:12 +0000 (11:06 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 28 Jun 2019 06:45:39 +0000 (08:45 +0200)
server/sonar-server/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java
server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesAction.java
server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesJsonWriter.java

index 35c491aa24cdd85e0c8a5da13cceb51e1f04f1c0..1f0698937a09007f8a030208ddcfd97173ade726 100644 (file)
@@ -44,7 +44,6 @@ import org.sonar.db.protobuf.DbIssues;
 import org.sonar.server.component.ws.ComponentViewerJsonWriter;
 import org.sonar.server.issue.IssueFinder;
 import org.sonar.server.source.SourceService;
-import org.sonar.server.user.UserSession;
 
 public class IssueSnippetsAction implements SourcesWsAction {
   private final IssueFinder issueFinder;
@@ -130,7 +129,7 @@ public class IssueSnippetsAction implements SourcesWsAction {
     componentViewerJsonWriter.writeComponentWithoutFav(writer, componentDto, dbSession, false);
     componentViewerJsonWriter.writeMeasures(writer, componentDto, dbSession);
     writer.endObject();
-    linesJsonWriter.writeSource(lineSources, writer, true, periodDateSupplier);
+    linesJsonWriter.writeSource(lineSources, writer, false, periodDateSupplier);
 
     writer.endObject();
   }
index eaa21aa709704bd4d209db1944b06bb2f053a19b..a7ecc8cb5ee18b6a77c311d06f76317cb01d4e56 100644 (file)
@@ -150,16 +150,14 @@ public class LinesAction implements SourcesWsAction {
       Iterable<DbFileSources.Line> lines = checkFoundWithOptional(sourceService.getLines(dbSession, file.uuid(), from, to), "No source found for file '%s'", file.getDbKey());
       try (JsonWriter json = response.newJsonWriter()) {
         json.beginObject();
-        linesJsonWriter.writeSource(lines, json, isMemberOfOrganization(dbSession, file), periodDateSupplier);
+        linesJsonWriter.writeSource(lines, json, isMemberOfOrganization(file), periodDateSupplier);
         json.endObject();
       }
     }
   }
 
-  private boolean isMemberOfOrganization(DbSession dbSession, ComponentDto file) {
-    OrganizationDto organizationDto = dbClient.organizationDao().selectByUuid(dbSession, file.getOrganizationUuid())
-      .orElseThrow(() -> new IllegalStateException(String.format("Organization with uuid '%s' not found", file.getOrganizationUuid())));
-    return !userSession.hasMembership(organizationDto);
+  private boolean isMemberOfOrganization(ComponentDto file) {
+    return userSession.hasMembership(new OrganizationDto().setUuid(file.getOrganizationUuid()));
   }
 
   private ComponentDto loadComponent(DbSession dbSession, Request wsRequest) {
index d85ac5d0a9952202c225d9c191224c3adf966ae8..3fba15c87c76c92d89f0dc00a6722e59d1954f73 100644 (file)
@@ -34,7 +34,7 @@ public class LinesJsonWriter {
     this.htmlSourceDecorator = htmlSourceDecorator;
   }
 
-  public void writeSource(Iterable<DbFileSources.Line> lines, JsonWriter json, boolean filterScmAuthors, Supplier<Optional<Long>> periodDateSupplier) {
+  public void writeSource(Iterable<DbFileSources.Line> lines, JsonWriter json, boolean showScmAuthors, Supplier<Optional<Long>> periodDateSupplier) {
     Optional<Long> periodDate = null;
 
     json.name("sources").beginArray();
@@ -43,7 +43,7 @@ public class LinesJsonWriter {
         .prop("line", line.getLine())
         .prop("code", htmlSourceDecorator.getDecoratedSourceAsHtml(line.getSource(), line.getHighlighting(), line.getSymbols()))
         .prop("scmRevision", line.getScmRevision());
-      if (!filterScmAuthors) {
+      if (showScmAuthors) {
         json.prop("scmAuthor", line.getScmAuthor());
       }
       if (line.hasScmDate()) {