From: Michal Duda Date: Thu, 25 Feb 2021 11:47:49 +0000 (+0100) Subject: SONAR-13848 remove deprecated params from /api/users/* WS X-Git-Tag: 8.8.0.42792~89 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=02a81396e81da8e2e93e73747fc185422697b67e;p=sonarqube.git SONAR-13848 remove deprecated params from /api/users/* WS --- diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CreateAction.java index 033adc3ed08..f7828f2f46a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CreateAction.java @@ -55,8 +55,6 @@ import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_LOGIN; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_NAME; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_PASSWORD; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SCM_ACCOUNT; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SCM_ACCOUNTS; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SCM_ACCOUNTS_DEPRECATED; public class CreateAction implements UsersWsAction { @@ -106,12 +104,6 @@ public class CreateAction implements UsersWsAction { .setDescription("User email") .setExampleValue("myname@email.com"); - action.createParam(PARAM_SCM_ACCOUNTS) - .setDescription("Comma-separated list of SCM accounts. This parameter is deprecated, please use '%s' instead", PARAM_SCM_ACCOUNT) - .setDeprecatedKey(PARAM_SCM_ACCOUNTS_DEPRECATED, "6.0") - .setDeprecatedSince("6.1") - .setExampleValue("myscmaccount1,myscmaccount2"); - action.createParam(PARAM_SCM_ACCOUNT) .setDescription("List of SCM accounts. To set several values, the parameter must be called once for each value.") .setExampleValue("scmAccount=firstValue&scmAccount=secondValue&scmAccount=thirdValue"); @@ -150,7 +142,8 @@ public class CreateAction implements UsersWsAction { })); } checkArgument(!existingUser.isActive(), "An active user with login '%s' already exists", login); - return buildResponse(userUpdater.reactivateAndCommit(dbSession, existingUser, newUser.build(), u -> {})); + return buildResponse(userUpdater.reactivateAndCommit(dbSession, existingUser, newUser.build(), u -> { + })); } } @@ -179,9 +172,9 @@ public class CreateAction implements UsersWsAction { private static List getScmAccounts(Request request) { if (request.hasParam(PARAM_SCM_ACCOUNT)) { return request.multiParam(PARAM_SCM_ACCOUNT); + } else { + return Collections.emptyList(); } - List oldScmAccounts = request.paramAsStrings(PARAM_SCM_ACCOUNTS); - return oldScmAccounts != null ? oldScmAccounts : Collections.emptyList(); } static class CreateRequest { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/UpdateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/UpdateAction.java index d2a1dd67fd0..55f43b6038b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/UpdateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/UpdateAction.java @@ -21,6 +21,7 @@ package org.sonar.server.user.ws; import com.google.common.base.Preconditions; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -55,8 +56,6 @@ import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_EMAIL; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_LOGIN; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_NAME; import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SCM_ACCOUNT; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SCM_ACCOUNTS; -import static org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SCM_ACCOUNTS_DEPRECATED; public class UpdateAction implements UsersWsAction { @@ -99,12 +98,6 @@ public class UpdateAction implements UsersWsAction { .setDescription("User email") .setExampleValue("myname@email.com"); - action.createParam(PARAM_SCM_ACCOUNTS) - .setDescription("This parameter is deprecated, please use '%s' instead", PARAM_SCM_ACCOUNT) - .setDeprecatedKey(PARAM_SCM_ACCOUNTS_DEPRECATED, "6.0") - .setDeprecatedSince("6.1") - .setExampleValue("myscmaccount1,myscmaccount2"); - action.createParam(PARAM_SCM_ACCOUNT) .setDescription("SCM accounts. To set several values, the parameter must be called once for each value.") .setExampleValue("scmAccount=firstValue&scmAccount=secondValue&scmAccount=thirdValue"); @@ -173,9 +166,9 @@ public class UpdateAction implements UsersWsAction { private static List getScmAccounts(Request request) { if (request.hasParam(PARAM_SCM_ACCOUNT)) { return new ArrayList<>(request.multiParam(PARAM_SCM_ACCOUNT)); + } else { + return Collections.emptyList(); } - List oldScmAccounts = request.paramAsStrings(PARAM_SCM_ACCOUNTS); - return oldScmAccounts != null ? oldScmAccounts : new ArrayList<>(); } private static class UpdateRequest { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java index cb096f96025..30fd3561fbd 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java @@ -183,34 +183,6 @@ public class CreateActionTest { .isEqualTo("john"); } - @Test - public void create_user_with_deprecated_scmAccounts_parameter() { - logInAsSystemAdministrator(); - - tester.newRequest() - .setParam("login", "john") - .setParam("name", "John") - .setParam("password", "1234") - .setParam("scmAccounts", "jn") - .execute(); - - assertThat(db.users().selectUserByLogin("john").get().getScmAccountsAsList()).containsOnly("jn"); - } - - @Test - public void create_user_with_deprecated_scm_accounts_parameter() { - logInAsSystemAdministrator(); - - tester.newRequest() - .setParam("login", "john") - .setParam("name", "John") - .setParam("password", "1234") - .setParam("scm_accounts", "jn") - .execute(); - - assertThat(db.users().selectUserByLogin("john").get().getScmAccountsAsList()).containsOnly("jn"); - } - @Test public void reactivate_user() { logInAsSystemAdministrator(); @@ -341,7 +313,7 @@ public class CreateActionTest { WebService.Action action = tester.getDef(); assertThat(action).isNotNull(); assertThat(action.isPost()).isTrue(); - assertThat(action.params()).hasSize(7); + assertThat(action.params()).hasSize(6); } private CreateWsResponse executeRequest(String login) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java index d5cdbedd5d6..e8f91d4b53d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java @@ -83,7 +83,6 @@ public class UpdateActionTest { .setParam("login", "john") .setParam("name", "Jon Snow") .setParam("email", "jon.snow@thegreatw.all") - .setParam("scmAccounts", "jon.snow") .execute() .assertJson(getClass(), "update_user.json"); } @@ -216,34 +215,6 @@ public class UpdateActionTest { assertThat(user.getScmAccountsAsList()).containsExactly("Jon.1", "JON.2", "jon.3"); } - @Test - public void update_only_scm_accounts_with_deprecated_scmAccounts_parameter() { - createUser(); - - ws.newRequest() - .setParam("login", "john") - .setParam("scmAccounts", "jon.snow") - .execute() - .assertJson(getClass(), "update_scm_accounts.json"); - - UserDto user = dbClient.userDao().selectByLogin(dbSession, "john"); - assertThat(user.getScmAccountsAsList()).containsOnly("jon.snow"); - } - - @Test - public void update_only_scm_accounts_with_deprecated_scm_accounts_parameter() { - createUser(); - - ws.newRequest() - .setParam("login", "john") - .setParam("scm_accounts", "jon.snow") - .execute() - .assertJson(getClass(), "update_scm_accounts.json"); - - UserDto user = dbClient.userDao().selectByLogin(dbSession, "john"); - assertThat(user.getScmAccountsAsList()).containsOnly("jon.snow"); - } - @Test public void fail_on_missing_permission() { createUser(); @@ -296,7 +267,7 @@ public class UpdateActionTest { WebService.Action action = ws.getDef(); assertThat(action).isNotNull(); assertThat(action.isPost()).isTrue(); - assertThat(action.params()).hasSize(5); + assertThat(action.params()).hasSize(4); } private void createUser() { diff --git a/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/user/ws/UpdateActionTest/update_user.json b/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/user/ws/UpdateActionTest/update_user.json index 4e5717b8cc2..d75fcbafe8c 100644 --- a/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/user/ws/UpdateActionTest/update_user.json +++ b/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/user/ws/UpdateActionTest/update_user.json @@ -3,7 +3,6 @@ "login": "john", "name": "Jon Snow", "email": "jon.snow@thegreatw.all", - "scmAccounts": ["jon.snow"], "active": true, "local": true } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java index fd15902dec0..08531d55e96 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java @@ -35,8 +35,7 @@ public class UsersWsParameters { public static final String PARAM_PASSWORD = "password"; public static final String PARAM_NAME = "name"; public static final String PARAM_EMAIL = "email"; - public static final String PARAM_SCM_ACCOUNTS = "scmAccounts"; - public static final String PARAM_SCM_ACCOUNTS_DEPRECATED = "scm_accounts"; + public static final String PARAM_SCM_ACCOUNT = "scmAccount"; public static final String PARAM_LOCAL = "local"; public static final String PARAM_SELECTED = "selected";