From cd6b35e42839c7992c520e1dd78d50edff268fde Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 12 Jun 2017 10:53:04 +0200 Subject: [PATCH] SONAR-9356 add "showOnboardingTutorial" in api/user/current --- .../java/org/sonar/server/user/ws/CurrentAction.java | 7 +++++-- .../org/sonar/server/user/ws/current-example.json | 1 + .../org/sonar/server/user/ws/CurrentActionTest.java | 12 +++++++----- sonar-ws/src/main/protobuf/ws-users.proto | 1 + 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/CurrentAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/CurrentAction.java index 36a208ca8ce..6d06d380fc8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/CurrentAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/CurrentAction.java @@ -22,6 +22,7 @@ package org.sonar.server.user.ws; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; +import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService.NewController; @@ -59,7 +60,8 @@ public class CurrentAction implements UsersWsAction { .setHandler(this) .setInternal(true) .setResponseExample(getClass().getResource("current-example.json")) - .setSince("5.2"); + .setSince("5.2") + .setChangelog(new Change("6.5", "showOnboardingTutorial is now returned in the response")); } @Override @@ -89,7 +91,8 @@ public class CurrentAction implements UsersWsAction { .setLocal(user.isLocal()) .addAllGroups(groups) .addAllScmAccounts(user.getScmAccountsAsList()) - .setPermissions(Permissions.newBuilder().addAllGlobal(getGlobalPermissions()).build()); + .setPermissions(Permissions.newBuilder().addAllGlobal(getGlobalPermissions()).build()) + .setShowOnboardingTutorial(!user.isOnboarded()); setNullable(emptyToNull(user.getEmail()), builder::setEmail); setNullable(user.getExternalIdentity(), builder::setExternalIdentity); setNullable(user.getExternalIdentityProvider(), builder::setExternalProvider); diff --git a/server/sonar-server/src/main/resources/org/sonar/server/user/ws/current-example.json b/server/sonar-server/src/main/resources/org/sonar/server/user/ws/current-example.json index 9237b50fe0e..77420e5fe9c 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/user/ws/current-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/user/ws/current-example.json @@ -6,6 +6,7 @@ "local": true, "externalIdentity": "obiwan.kenobi", "externalProvider": "sonarqube", + "showOnboardingTutorial": false, "scmAccounts": [ "obiwan:github", "obiwan:bitbucket" diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java index fe623c05cce..a5b9f4b3f10 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CurrentActionTest.java @@ -63,16 +63,17 @@ public class CurrentActionTest { .setLocal(true) .setExternalIdentity("obiwan") .setExternalIdentityProvider("sonarqube") - .setScmAccounts(newArrayList("obiwan:github", "obiwan:bitbucket"))); + .setScmAccounts(newArrayList("obiwan:github", "obiwan:bitbucket")) + .setOnboarded(false)); userSessionRule.logIn("obiwan.kenobi"); CurrentWsResponse response = call(); assertThat(response) .extracting(CurrentWsResponse::getIsLoggedIn, CurrentWsResponse::getLogin, CurrentWsResponse::getName, CurrentWsResponse::getEmail, CurrentWsResponse::getLocal, - CurrentWsResponse::getExternalIdentity, CurrentWsResponse::getExternalProvider, CurrentWsResponse::getScmAccountsList) + CurrentWsResponse::getExternalIdentity, CurrentWsResponse::getExternalProvider, CurrentWsResponse::getScmAccountsList, CurrentWsResponse::getShowOnboardingTutorial) .containsExactly(true, "obiwan.kenobi", "Obiwan Kenobi", "obiwan.kenobi@starwars.com", true, "obiwan", "sonarqube", - newArrayList("obiwan:github", "obiwan:bitbucket")); + newArrayList("obiwan:github", "obiwan:bitbucket"), true); } @Test @@ -182,7 +183,8 @@ public class CurrentActionTest { .setLocal(true) .setExternalIdentity("obiwan.kenobi") .setExternalIdentityProvider("sonarqube") - .setScmAccounts(newArrayList("obiwan:github", "obiwan:bitbucket"))); + .setScmAccounts(newArrayList("obiwan:github", "obiwan:bitbucket")) + .setOnboarded(true)); db.users().insertMember(db.users().insertGroup(newGroupDto().setName("Jedi")), obiwan); db.users().insertMember(db.users().insertGroup(newGroupDto().setName("Rebel")), obiwan); @@ -201,7 +203,7 @@ public class CurrentActionTest { assertThat(definition.isInternal()).isTrue(); assertThat(definition.responseExampleAsString()).isNotEmpty(); assertThat(definition.params()).isEmpty(); - assertThat(definition.changelog()).isEmpty(); + assertThat(definition.changelog()).hasSize(1); } private CurrentWsResponse call() { diff --git a/sonar-ws/src/main/protobuf/ws-users.proto b/sonar-ws/src/main/protobuf/ws-users.proto index 0eddebed940..c71a3395f2d 100644 --- a/sonar-ws/src/main/protobuf/ws-users.proto +++ b/sonar-ws/src/main/protobuf/ws-users.proto @@ -105,6 +105,7 @@ message CurrentWsResponse { repeated string scmAccounts = 8; repeated string groups = 9; optional Permissions permissions = 10; + optional bool showOnboardingTutorial = 11; message Permissions { repeated string global = 1; -- 2.39.5