From c6726e9207d56c672c3b4cdd21f4968cdd17a29a Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 23 Mar 2017 16:20:15 +0100 Subject: SONAR-8969 Replace user email by avatar in issues WS --- sonar-ws/src/main/protobuf/ws-commons.proto | 11 ----------- sonar-ws/src/main/protobuf/ws-issues.proto | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'sonar-ws') diff --git a/sonar-ws/src/main/protobuf/ws-commons.proto b/sonar-ws/src/main/protobuf/ws-commons.proto index 6f9c6805103..50a4fa4268c 100644 --- a/sonar-ws/src/main/protobuf/ws-commons.proto +++ b/sonar-ws/src/main/protobuf/ws-commons.proto @@ -72,17 +72,6 @@ enum RuleStatus { REMOVED = 3; } -message User { - optional string login = 1; - optional string name = 2; - optional string email = 3; - optional bool active = 4; -} - -message Users { - repeated User users = 1; -} - // Lines start at 1 and line offsets start at 0 message TextRange { // Start line. Should never be absent diff --git a/sonar-ws/src/main/protobuf/ws-issues.proto b/sonar-ws/src/main/protobuf/ws-issues.proto index a2d1aa67a2f..361efbd4a92 100644 --- a/sonar-ws/src/main/protobuf/ws-issues.proto +++ b/sonar-ws/src/main/protobuf/ws-issues.proto @@ -41,7 +41,7 @@ message SearchWsResponse { repeated Issue issues = 6; repeated Component components = 7; optional sonarqube.ws.commons.Rules rules = 8; - optional sonarqube.ws.commons.Users users = 9; + optional Users users = 9; // Deprecated since 5.5, action plan has been removed optional ActionPlans unusedActionPlans = 10; @@ -54,7 +54,7 @@ message Operation { optional Issue issue = 1; repeated Component components = 2; repeated sonarqube.ws.commons.Rule rules = 3; - repeated sonarqube.ws.commons.User users = 4; + repeated Users.User users = 4; // Deprecated since 5.5, action plan has been removed repeated ActionPlan actiunusedActionPlansonPlans = 5; } @@ -211,5 +211,16 @@ message BulkChangeWsResponse { optional int64 failures = 4; } +message Users { + repeated User users = 1; + + message User { + optional string login = 1; + optional string name = 2; + optional string avatar = 3; + optional bool active = 4; + } +} + -- cgit v1.2.3 From f90f904436231604f842d4bca99f8508ca2e664a Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 24 Mar 2017 08:43:02 +0100 Subject: SONAR-8969 Replace user email by avatar in issue changelog WS --- .../java/org/sonar/server/issue/ws/ChangelogAction.java | 9 ++++++++- .../org/sonar/server/issue/ws/changelog-example.json | 2 +- .../org/sonar/server/issue/ws/ChangelogActionTest.java | 15 +++++++++++---- sonar-ws/src/main/protobuf/ws-issues.proto | 4 +++- 4 files changed, 23 insertions(+), 7 deletions(-) (limited to 'sonar-ws') diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java index e0d84be5a7a..9ce3289b3fa 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java @@ -19,6 +19,7 @@ */ package org.sonar.server.issue.ws; +import com.google.common.hash.Hashing; import com.google.common.io.Resources; import java.util.List; import java.util.Map; @@ -43,6 +44,8 @@ import org.sonarqube.ws.Issues.ChangelogWsResponse; import org.sonarqube.ws.Issues.ChangelogWsResponse.Changelog; import static com.google.common.base.Strings.emptyToNull; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Locale.ENGLISH; import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.core.util.Protobuf.setNullable; import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01; @@ -116,7 +119,7 @@ public class ChangelogAction implements IssuesWsAction { if (user != null) { changelogBuilder.setUser(user.getLogin()); changelogBuilder.setUserName(user.getName()); - setNullable(emptyToNull(user.getEmail()), changelogBuilder::setEmail); + setNullable(emptyToNull(user.getEmail()), c -> changelogBuilder.setAvatar(hash(c))); } change.diffs().entrySet().stream() .map(toWsDiff(results)) @@ -143,6 +146,10 @@ public class ChangelogAction implements IssuesWsAction { }; } + private static String hash(String text) { + return Hashing.md5().hashString(text.toLowerCase(ENGLISH), UTF_8).toString(); + } + private class ChangeLogResults { private final List changes; private final Map users; diff --git a/server/sonar-server/src/main/resources/org/sonar/server/issue/ws/changelog-example.json b/server/sonar-server/src/main/resources/org/sonar/server/issue/ws/changelog-example.json index 7d962cbb001..32d17a9c7aa 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/issue/ws/changelog-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/issue/ws/changelog-example.json @@ -3,7 +3,7 @@ { "user": "john.smith", "userName": "John Smith", - "email": "john@smith.com", + "avatar": "b0d8c6e5ea589e6fc3d3e08afb1873bb" "creationDate": "2014-03-04T23:03:44+0100", "diffs": [ { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java index 17df8dd97f6..96783929bd1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java @@ -20,6 +20,7 @@ package org.sonar.server.issue.ws; import com.google.common.base.Throwables; +import com.google.common.hash.Hashing; import java.io.IOException; import javax.annotation.Nullable; import org.junit.Rule; @@ -44,6 +45,8 @@ import org.sonarqube.ws.Issues.ChangelogWsResponse; import org.sonarqube.ws.Issues.ChangelogWsResponse.Changelog.Diff; import org.sonarqube.ws.MediaTypes; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Locale.ENGLISH; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.groups.Tuple.tuple; import static org.sonar.api.web.UserRole.CODEVIEWER; @@ -80,7 +83,7 @@ public class ChangelogActionTest { assertThat(result.getChangelogList()).hasSize(1); assertThat(result.getChangelogList().get(0).getUser()).isNotNull().isEqualTo(user.getLogin()); assertThat(result.getChangelogList().get(0).getUserName()).isNotNull().isEqualTo(user.getName()); - assertThat(result.getChangelogList().get(0).getEmail()).isNotNull().isEqualTo(user.getEmail()); + assertThat(result.getChangelogList().get(0).getAvatar()).isNotNull().isEqualTo(hash(user.getEmail())); assertThat(result.getChangelogList().get(0).getCreationDate()).isNotEmpty(); assertThat(result.getChangelogList().get(0).getDiffsList()).extracting(Diff::getKey, Diff::getOldValue, Diff::getNewValue).containsOnly(tuple("severity", "MAJOR", "BLOCKER")); } @@ -129,7 +132,7 @@ public class ChangelogActionTest { assertThat(result.getChangelogList()).hasSize(1); assertThat(result.getChangelogList().get(0).getUser()).isNotNull().isEqualTo(user.getLogin()); assertThat(result.getChangelogList().get(0).getUserName()).isNotNull().isEqualTo(user.getName()); - assertThat(result.getChangelogList().get(0).hasEmail()).isFalse(); + assertThat(result.getChangelogList().get(0).hasAvatar()).isFalse(); } @Test @@ -143,7 +146,7 @@ public class ChangelogActionTest { assertThat(result.getChangelogList()).hasSize(1); assertThat(result.getChangelogList().get(0).hasUser()).isFalse(); assertThat(result.getChangelogList().get(0).hasUserName()).isFalse(); - assertThat(result.getChangelogList().get(0).hasEmail()).isFalse(); + assertThat(result.getChangelogList().get(0).hasAvatar()).isFalse(); assertThat(result.getChangelogList().get(0).getDiffsList()).isNotEmpty(); } @@ -158,7 +161,7 @@ public class ChangelogActionTest { assertThat(result.getChangelogList()).hasSize(1); assertThat(result.getChangelogList().get(0).hasUser()).isFalse(); assertThat(result.getChangelogList().get(0).hasUserName()).isFalse(); - assertThat(result.getChangelogList().get(0).hasEmail()).isFalse(); + assertThat(result.getChangelogList().get(0).hasAvatar()).isFalse(); assertThat(result.getChangelogList().get(0).getDiffsList()).isNotEmpty(); } @@ -291,4 +294,8 @@ public class ChangelogActionTest { return newDto(rule, file, project); } + private static String hash(String text) { + return Hashing.md5().hashString(text.toLowerCase(ENGLISH), UTF_8).toString(); + } + } diff --git a/sonar-ws/src/main/protobuf/ws-issues.proto b/sonar-ws/src/main/protobuf/ws-issues.proto index 361efbd4a92..4e31149efcf 100644 --- a/sonar-ws/src/main/protobuf/ws-issues.proto +++ b/sonar-ws/src/main/protobuf/ws-issues.proto @@ -191,9 +191,11 @@ message ChangelogWsResponse { message Changelog { optional string user = 1; optional string userName = 2; - optional string email = 3; + // Email is no more returned since 6.3 + optional string deprecatedEmail = 3; optional string creationDate = 4; repeated Diff diffs = 5; + optional string avatar = 6; message Diff { optional string key = 1; -- cgit v1.2.3