Browse Source

SONAR-13848 remove deprecated params from /api/users/* WS

tags/8.8.0.42792
Michal Duda 3 years ago
parent
commit
02a81396e8

+ 4
- 11
server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CreateAction.java View 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 {

+ 3
- 10
server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/UpdateAction.java View 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 {

+ 1
- 29
server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java View 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) {

+ 1
- 30
server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java View 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() {

+ 0
- 1
server/sonar-webserver-webapi/src/test/resources/org/sonar/server/user/ws/UpdateActionTest/update_user.json View File

@@ -3,7 +3,6 @@
"login": "john",
"name": "Jon Snow",
"email": "jon.snow@thegreatw.all",
"scmAccounts": ["jon.snow"],
"active": true,
"local": true
}

+ 1
- 2
sonar-ws/src/main/java/org/sonarqube/ws/client/user/UsersWsParameters.java View 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";

Loading…
Cancel
Save