use of com.thoughtworks.go.server.exceptions.UserEnabledException in project gocd by gocd.
the class UserServiceTest method shouldFailWithErrorWhenDeletingAnEnabledUserFails.
@Test
void shouldFailWithErrorWhenDeletingAnEnabledUserFails() {
String username = "username";
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(userDao.deleteUser(username, "currentUser")).thenThrow(new UserEnabledException());
userService.deleteUser(username, "currentUser", result);
assertThat(result.isSuccessful()).isFalse();
assertThat(result.hasMessage()).isTrue();
}
use of com.thoughtworks.go.server.exceptions.UserEnabledException in project gocd by gocd.
the class UserSqlMapDao method deleteUser.
@Override
public boolean deleteUser(final String username, String byWhom) {
return (Boolean) transactionTemplate.execute((TransactionCallback) status -> {
User user = findUser(username);
if (user instanceof NullUser) {
throw new RecordNotFoundException(EntityType.User, username);
}
if (user.isEnabled()) {
throw new UserEnabledException();
}
sessionFactory.getCurrentSession().delete(user);
accessTokenDao.revokeTokensBecauseOfUserDelete(Collections.singletonList(username), byWhom);
return Boolean.TRUE;
});
}
Aggregations