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;
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();
}
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) {
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();
.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()) {