import org.sonar.api.platform.NewUserHandler;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.System2;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserGroupDto;
-import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.Message;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.index.UserDoc;
import org.sonar.server.user.index.UserIndex;
+import static com.google.common.base.Strings.emptyToNull;
+
public class UpdateAction implements UsersWsAction {
private static final String PARAM_LOGIN = "login";
updateUser.setName(request.mandatoryParam(PARAM_NAME));
}
if (request.hasParam(PARAM_EMAIL)) {
- updateUser.setEmail(request.param(PARAM_EMAIL));
+ updateUser.setEmail(emptyToNull(request.param(PARAM_EMAIL)));
}
if (request.hasParam(PARAM_SCM_ACCOUNTS) || request.hasParam(PARAM_SCM_ACCOUNTS_DEPRECATED)) {
updateUser.setScmAccounts(request.paramAsStrings(PARAM_SCM_ACCOUNTS));
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.user.GroupDao;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.GroupMembershipDao;
+import org.sonar.db.user.UserDao;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserGroupDao;
-import org.sonar.server.db.DbClient;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.NewUserNotifier;
import org.sonar.server.user.SecurityRealmFactory;
import org.sonar.server.user.UserUpdater;
-import org.sonar.db.user.GroupDao;
-import org.sonar.db.user.UserDao;
import org.sonar.server.user.index.UserIndex;
import org.sonar.server.user.index.UserIndexDefinition;
import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.ws.WsTester;
import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
public class UpdateActionTest {
public static final EsTester esTester = new EsTester().addDefinitions(new UserIndexDefinition(settings));
@Rule
public final UserSessionRule userSessionRule = UserSessionRule.standalone().login("admin")
- .setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ .setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
WebService.Controller controller;
.assertJson(getClass(), "update_email.json");
}
+ @Test
+ public void blank_email_is_updated_to_null() throws Exception {
+ createUser();
+
+ tester.newPostRequest("api/users", "update")
+ .setParam("login", "john")
+ .setParam("email", "")
+ .execute()
+ .assertJson(getClass(), "blank_email_is_updated_to_null.json");
+
+ UserDto userDto = dbClient.userDao().selectByLogin(session, "john");
+ assertThat(userDto.getEmail()).isNull();
+ }
+
@Test
public void update_only_scm_accounts() throws Exception {
createUser();
.setLogin("john")
.setName("John")
.setScmAccounts(newArrayList("jn"))
- .setActive(true));
+ .setActive(true))
+ .setExternalIdentity("jo")
+ .setExternalIdentityProvider("sonarqube");
session.commit();
userIndexer.index();
}