use of org.sonarqube.ws.Users.CreateWsResponse in project sonarqube by SonarSource.
the class CreateAction method doHandle.
private CreateWsResponse doHandle(CreateRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
String login = request.getLogin();
NewUser.Builder newUser = NewUser.builder().setLogin(login).setName(request.getName()).setEmail(request.getEmail()).setScmAccounts(request.getScmAccounts()).setPassword(request.getPassword());
if (!request.isLocal()) {
newUser.setExternalIdentity(new ExternalIdentity(SQ_AUTHORITY, login, login));
}
UserDto existingUser = dbClient.userDao().selectByLogin(dbSession, login);
if (existingUser == null) {
return buildResponse(userUpdater.createAndCommit(dbSession, newUser.build(), u -> {
}));
}
checkArgument(!existingUser.isActive(), "An active user with login '%s' already exists", login);
return buildResponse(userUpdater.reactivateAndCommit(dbSession, existingUser, newUser.build(), u -> {
}));
}
}
use of org.sonarqube.ws.Users.CreateWsResponse in project sonarqube by SonarSource.
the class CreateActionTest method create_user_with_comma_in_scm_account.
@Test
public void create_user_with_comma_in_scm_account() {
logInAsSystemAdministrator();
CreateWsResponse response = call(CreateRequest.builder().setLogin("john").setName("John").setEmail("john@email.com").setScmAccounts(singletonList("j,n")).setPassword("1234").build());
assertThat(response.getUser().getScmAccountsList()).containsOnly("j,n");
}
use of org.sonarqube.ws.Users.CreateWsResponse in project sonarqube by SonarSource.
the class CreateActionTest method create_user.
@Test
public void create_user() {
logInAsSystemAdministrator();
CreateWsResponse response = call(CreateRequest.builder().setLogin("john").setName("John").setEmail("john@email.com").setScmAccounts(singletonList("jn")).setPassword("1234").build());
assertThat(response.getUser()).extracting(User::getLogin, User::getName, User::getEmail, User::getScmAccountsList, User::getLocal).containsOnly("john", "John", "john@email.com", singletonList("jn"), true);
// exists in index
assertThat(es.client().search(EsClient.prepareSearch(UserIndexDefinition.TYPE_USER).source(new SearchSourceBuilder().query(boolQuery().must(termQuery(FIELD_LOGIN, "john")).must(termQuery(FIELD_NAME, "John")).must(termQuery(FIELD_EMAIL, "john@email.com")).must(termQuery(FIELD_SCM_ACCOUNTS, "jn"))))).getHits().getHits()).hasSize(1);
// exists in db
Optional<UserDto> dbUser = db.users().selectUserByLogin("john");
assertThat(dbUser).isPresent();
assertThat(dbUser.get().isRoot()).isFalse();
// member of default group
assertThat(db.users().selectGroupUuidsOfUser(dbUser.get())).containsOnly(defaultGroup.getUuid());
}
Aggregations