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