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);
}
}
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) {
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);
}
}
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);
}
}
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);
}
}
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);
}
// 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());
return options;
}
- options.addFacets(facets);
+ List<String> requestedFacets = new ArrayList<>(facets);
+ if (!userSession.isLoggedIn()) {
+ requestedFacets.remove(PARAM_AUTHOR);
+ }
+ options.addFacets(requestedFacets);
return options;
}
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)) {
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());
.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()));
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()));
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);
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));
}
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);
}
}
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) {
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);
}
}
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();
}
"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();
}
}
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();
.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())));
}
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);
}
}
- 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;
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();
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);
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);
}
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();
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();
@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();
.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"));
@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());
@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());
@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);
@Test
public void formatOperation_should_add_issue_to_response() {
- Operation result = searchResponseFormat.formatOperation(searchResponseData);
+ Operation result = searchResponseFormat.formatOperation(searchResponseData, true);
assertIssueEqualsIssueDto(result.getIssue(), issueDto);
}
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());
}
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");
}
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());
}
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);
}
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);
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());
}
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());
}
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);
}
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);
}
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());
}
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();
}
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());
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");
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());
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;
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
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
@Test
public void show_scm() {
+ userSessionRule.logIn();
userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
.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()
@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)
@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)
@Test
public void accept_negative_value_in_from_parameter() {
+ userSessionRule.logIn();
userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
-{
- "sources": [
- {
- "line": 1,
- "code": "\u003cp\u003eSOURCE_1\u003c/p\u003e",
- "scmRevision": "REVISION_1",
- "scmDate": "1974-10-03T03:40:00+0100",
- "duplicated": false,
- "isNew": false
- }
- ]
-}
--- /dev/null
+{
+ "scm": [
+ [1, "","2015-03-30T12:34:56+0000", "123-456-789"]
+ ]
+}