diff options
author | Lukasz Jarocki <lukasz.jarocki@sonarsource.com> | 2021-10-01 09:01:49 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-10-01 20:03:19 +0000 |
commit | abb09faf00e8ea3b03642705ca2d42440336bf28 (patch) | |
tree | 8850aa9c7b9a4f1479430db56defd410ad1c9a0a | |
parent | 9d7dac07bd5584f8de57e0dfefc9e4da51f31de0 (diff) | |
download | sonarqube-abb09faf00e8ea3b03642705ca2d42440336bf28.tar.gz sonarqube-abb09faf00e8ea3b03642705ca2d42440336bf28.zip |
SONAR-15458 update /api/users/current to return information about usage of sonarlint
4 files changed, 19 insertions, 5 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java index 877c98eac1f..6487c01d91a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java @@ -86,7 +86,8 @@ public class CurrentAction implements UsersWsAction { .setResponseExample(getClass().getResource("current-example.json")) .setChangelog( new Change("6.5", "showOnboardingTutorial is now returned in the response"), - new Change("7.1", "'parameter' is replaced by 'component' and 'organization' in the response")); + new Change("7.1", "'parameter' is replaced by 'component' and 'organization' in the response"), + new Change("9.2", "boolean 'usingSonarLintConnectedMode' field is now returned in the response")); } @Override @@ -119,7 +120,8 @@ public class CurrentAction implements UsersWsAction { .setPermissions(Permissions.newBuilder().addAllGlobal(getGlobalPermissions()).build()) .setHomepage(buildHomepage(dbSession, user)) .setShowOnboardingTutorial(!user.isOnboarded()) - .addAllSettings(loadUserSettings(dbSession, user)); + .addAllSettings(loadUserSettings(dbSession, user)) + .setUsingSonarLintConnectedMode(user.getLastSonarlintConnectionDate() != null); ofNullable(emptyToNull(user.getEmail())).ifPresent(builder::setEmail); ofNullable(emptyToNull(user.getEmail())).ifPresent(u -> builder.setAvatar(avatarResolver.create(user))); ofNullable(user.getExternalLogin()).ifPresent(builder::setExternalIdentity); diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/user/ws/current-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/user/ws/current-example.json index 7bd1e6b84e0..202457e4e3d 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/user/ws/current-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/user/ws/current-example.json @@ -10,6 +10,7 @@ "showOnboardingTutorial": false, "scmAccounts": ["obiwan:github", "obiwan:bitbucket"], "groups": ["Jedi", "Rebel"], + "usingSonarLintConnectedMode": false, "permissions": { "global": ["profileadmin", "scan"] }, diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java index 8f5abb76293..e8e7d23fd55 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java @@ -103,8 +103,8 @@ public class CurrentActionTest { assertThat(response) .extracting(CurrentWsResponse::getIsLoggedIn, CurrentWsResponse::getLogin, CurrentWsResponse::getName, CurrentWsResponse::hasAvatar, CurrentWsResponse::getLocal, - CurrentWsResponse::getExternalIdentity, CurrentWsResponse::getExternalProvider, CurrentWsResponse::getSettingsList) - .containsExactly(true, "obiwan.kenobi", "Obiwan Kenobi", false, true, "obiwan", "sonarqube", Collections.emptyList()); + CurrentWsResponse::getExternalIdentity, CurrentWsResponse::getExternalProvider, CurrentWsResponse::getSettingsList, CurrentWsResponse::getUsingSonarLintConnectedMode) + .containsExactly(true, "obiwan.kenobi", "Obiwan Kenobi", false, true, "obiwan", "sonarqube", Collections.emptyList(), false); assertThat(response.hasEmail()).isFalse(); assertThat(response.getScmAccountsList()).isEmpty(); assertThat(response.getGroupsList()).isEmpty(); @@ -225,6 +225,16 @@ public class CurrentActionTest { } @Test + public void handle_givenSonarLintUserInDatabase_returnSonarLintUserFromTheEndpoint() { + UserDto user = db.users().insertUser(u -> u.setLastSonarlintConnectionDate(System.currentTimeMillis())); + userSession.logIn(user); + + CurrentWsResponse response = call(); + + assertThat(response.getUsingSonarLintConnectedMode()).isTrue(); + } + + @Test public void test_definition() { WebService.Action definition = ws.getDef(); assertThat(definition.key()).isEqualTo("current"); @@ -234,7 +244,7 @@ public class CurrentActionTest { assertThat(definition.isInternal()).isTrue(); assertThat(definition.responseExampleAsString()).isNotEmpty(); assertThat(definition.params()).isEmpty(); - assertThat(definition.changelog()).hasSize(2); + assertThat(definition.changelog()).hasSize(3); } private CurrentWsResponse call() { diff --git a/sonar-ws/src/main/protobuf/ws-users.proto b/sonar-ws/src/main/protobuf/ws-users.proto index 7b44cbf71c1..6a6ff1b0219 100644 --- a/sonar-ws/src/main/protobuf/ws-users.proto +++ b/sonar-ws/src/main/protobuf/ws-users.proto @@ -111,6 +111,7 @@ message CurrentWsResponse { optional string avatar = 12; optional Homepage homepage = 13; repeated Setting settings = 15; + optional bool usingSonarLintConnectedMode = 16; message Permissions { repeated string global = 1; |