]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13848 remove deprecated params from /api/users/* WS
authorMichal Duda <michal.duda@sonarsource.com>
Thu, 25 Feb 2021 11:47:49 +0000 (12:47 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 26 Feb 2021 20:07:41 +0000 (20:07 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CreateAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/UpdateAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
server/sonar-webserver-webapi/src/test/resources/org/sonar/server/user/ws/UpdateActionTest/update_user.json
sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java

index 033adc3ed080b64a7b885a4f9ca6362c3a6fde49..f7828f2f46a118d0b1ce630a7256e127162ab9ae 100644 (file)
@@ -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<String> getScmAccounts(Request request) {
     if (request.hasParam(PARAM_SCM_ACCOUNT)) {
       return request.multiParam(PARAM_SCM_ACCOUNT);
+    } else {
+      return Collections.emptyList();
     }
-    List<String> oldScmAccounts = request.paramAsStrings(PARAM_SCM_ACCOUNTS);
-    return oldScmAccounts != null ? oldScmAccounts : Collections.emptyList();
   }
 
   static class CreateRequest {
index d2a1dd67fd06df4f186624311ae8517195d1a338..55f43b6038b8058d28bf57a202e0da50ae4fae12 100644 (file)
@@ -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<String> getScmAccounts(Request request) {
     if (request.hasParam(PARAM_SCM_ACCOUNT)) {
       return new ArrayList<>(request.multiParam(PARAM_SCM_ACCOUNT));
+    } else {
+      return Collections.emptyList();
     }
-    List<String> oldScmAccounts = request.paramAsStrings(PARAM_SCM_ACCOUNTS);
-    return oldScmAccounts != null ? oldScmAccounts : new ArrayList<>();
   }
 
   private static class UpdateRequest {
index cb096f96025e3fa121ad938e2bd3e31645f52688..30fd3561fbda7c530e04e8d7bc3f2eb3966ab35d 100644 (file)
@@ -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) {
index d5cdbedd5d6c55c21520c2a4e7697cf07559d29b..e8f91d4b53dc9f6be7d86d1b3b0ca57891d1bc18 100644 (file)
@@ -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() {
index 4e5717b8cc25527eb84510b842d0a6bab7c6831c..d75fcbafe8c562b0647134cae7ecadc444384ecc 100644 (file)
@@ -3,7 +3,6 @@
     "login": "john",
     "name": "Jon Snow",
     "email": "jon.snow@thegreatw.all",
-    "scmAccounts": ["jon.snow"],
     "active": true,
     "local": true
   }
index fd15902dec04aca31c6a5740809452b38359ccb1..08531d55e96086c2d75ed4416af7d481e284cc3e 100644 (file)
@@ -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";