From abb09faf00e8ea3b03642705ca2d42440336bf28 Mon Sep 17 00:00:00 2001 From: Lukasz Jarocki Date: Fri, 1 Oct 2021 09:01:49 +0200 Subject: [PATCH] SONAR-15458 update /api/users/current to return information about usage of sonarlint --- .../org/sonar/server/user/ws/CurrentAction.java | 6 ++++-- .../sonar/server/user/ws/current-example.json | 1 + .../sonar/server/user/ws/CurrentActionTest.java | 16 +++++++++++++--- sonar-ws/src/main/protobuf/ws-users.proto | 1 + 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(); @@ -224,6 +224,16 @@ public class CurrentActionTest { assertJson(response).isSimilarTo(getClass().getResource("current-example.json")); } + @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(); @@ -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; -- 2.39.5