use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.
the class UserService method create.
public void create(List<UserSearchModel> userSearchModels, HttpLocalizedOperationResult result) {
if (userSearchModels.isEmpty()) {
result.badRequest(LocalizedMessage.string("NO_USERS_SELECTED"));
return;
}
synchronized (enableUserMutex) {
for (UserSearchModel userSearchModel : userSearchModels) {
User user = userSearchModel.getUser();
if (userExists(user)) {
result.conflict(LocalizedMessage.string("RESOURCE_ALREADY_EXISTS", "user", user.getName(), user.getDisplayName(), user.getEmail()));
return;
}
if (user.isAnonymous()) {
result.badRequest(LocalizedMessage.string("USERNAME_NOT_PERMITTED", user.getName()));
return;
}
if (!userSearchModel.getUserSourceType().equals(UserSourceType.PASSWORD_FILE) && validate(result, user)) {
return;
}
userDao.saveOrUpdate(user);
result.setMessage(LocalizedMessage.string("USER_SUCCESSFULLY_ADDED", user.getName()));
}
}
}
use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.
the class UserServiceTest method shouldCreateNewUsers.
@Test
public void shouldCreateNewUsers() throws Exception {
UserSearchModel foo = new UserSearchModel(new User("fooUser", "Mr Foo", "foo@cruise.com"), UserSourceType.LDAP);
doNothing().when(userDao).saveOrUpdate(foo.getUser());
when(userDao.findUser("fooUser")).thenReturn(new NullUser());
when(userDao.enabledUserCount()).thenReturn(10);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
userService.create(Arrays.asList(foo), result);
assertThat(result.isSuccessful(), is(true));
}
use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.
the class UserServiceIntegrationTest method shouldReturnErrorWhenUserAlreadyExists.
@Test
public void shouldReturnErrorWhenUserAlreadyExists() throws Exception {
UserSearchModel foo = new UserSearchModel(new User("fooUser", "Mr Foo", "foo@cruise.com"), UserSourceType.LDAP);
addUser(foo.getUser());
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
userService.create(Arrays.asList(foo), result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.message(localizer), is("Failed to add user. The user 'fooUser' already exists."));
}
use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.
the class UserServiceIntegrationTest method shouldReturnErrorMessageWhenUserValidationsFail.
@Test
public void shouldReturnErrorMessageWhenUserValidationsFail() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
User invalidUser = new User("fooUser", "Foo User", "invalidEmail");
UserSearchModel searchModel = new UserSearchModel(invalidUser, UserSourceType.LDAP);
userService.create(Arrays.asList(searchModel), result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.message(localizer), is("Failed to add user. Validations failed. Invalid email address."));
}
use of com.thoughtworks.go.presentation.UserSearchModel in project gocd by gocd.
the class UserSearchServiceTest method shouldNotReturnWarningMessageWhenPasswordFileIsNotConfigured.
@Test
public void shouldNotReturnWarningMessageWhenPasswordFileIsNotConfigured() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(goConfigService.isPasswordFileConfigured()).thenReturn(false);
when(ldapUserSearch.search("foo")).thenReturn(Arrays.asList(new User("foo")));
List<UserSearchModel> models = userSearchService.search("foo", result);
assertThat(models.size(), is(1));
assertThat(result.hasMessage(), is(false));
}
Aggregations