From cc62adb150fe70a68af9f01f26a0828cd111e2d1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 18 Jun 2019 11:06:12 +0200 Subject: [PATCH] SONAR-12075 remove double negative boolean and a SQL request --- .../org/sonar/server/source/ws/IssueSnippetsAction.java | 3 +-- .../main/java/org/sonar/server/source/ws/LinesAction.java | 8 +++----- .../java/org/sonar/server/source/ws/LinesJsonWriter.java | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java b/server/sonar-server/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java index 35c491aa24c..1f0698937a0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java @@ -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(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesAction.java b/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesAction.java index eaa21aa7097..a7ecc8cb5ee 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesAction.java @@ -150,16 +150,14 @@ public class LinesAction implements SourcesWsAction { Iterable 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) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesJsonWriter.java b/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesJsonWriter.java index d85ac5d0a99..3fba15c87c7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesJsonWriter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/source/ws/LinesJsonWriter.java @@ -34,7 +34,7 @@ public class LinesJsonWriter { this.htmlSourceDecorator = htmlSourceDecorator; } - public void writeSource(Iterable lines, JsonWriter json, boolean filterScmAuthors, Supplier> periodDateSupplier) { + public void writeSource(Iterable lines, JsonWriter json, boolean showScmAuthors, Supplier> periodDateSupplier) { Optional 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()) { -- 2.39.5