@@ -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 { |
@@ -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 { |
@@ -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) { |
@@ -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() { |
@@ -3,7 +3,6 @@ | |||
"login": "john", | |||
"name": "Jon Snow", | |||
"email": "jon.snow@thegreatw.all", | |||
"scmAccounts": ["jon.snow"], | |||
"active": true, | |||
"local": true | |||
} |
@@ -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"; |