private void flagAdminUserAsRoot(DbSession dbSession, String login) { dbClient.userDao().setRoot(dbSession, login, true); }
private UserDto insertRootUser(UserDto dto) { insertNonRootUser(dto); userDao.setRoot(dbSession, dto.getLogin(), true); dbSession.commit(); return dto; }
private UserDto insertRootUser(UserDto dto) { underTest.insert(session, dto); underTest.setRoot(session, dto.getLogin(), true); session.commit(); return dto; }
@Test public void execute_succeeds_when_root_user_has_neither_email_nor_name() { logInAsRoot(); UserDto rootDto = userDao.insert(dbSession, UserTesting.newUserDto().setName(null).setEmail(null)); userDao.setRoot(dbSession, rootDto.getLogin(), true); dbSession.commit(); List<Roots.RootContent> roots = executeRequest(); assertThat(roots).hasSize(1); Roots.RootContent root = roots.iterator().next(); assertThat(root.getLogin()).isEqualTo(rootDto.getLogin()); assertThat(root.hasName()).isFalse(); assertThat(root.hasEmail()).isFalse(); }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkIsRoot(); String login = request.mandatoryParam(PARAM_LOGIN); try (DbSession dbSession = dbClient.openSession(false)) { UserDto userDto = dbClient.userDao().selectByLogin(dbSession, login); if (userDto == null || !userDto.isActive()) { throw new NotFoundException(format("User with login '%s' not found", login)); } if (!userDto.isRoot()) { dbClient.userDao().setRoot(dbSession, login, true); dbSession.commit(); } } response.noContent(); }
@Test public void setRoot_has_no_effect_on_root_flag_of_inactive_user() { String nonRootInactiveUser = insertUser(false).getLogin(); commit(() -> underTest.setRoot(session, nonRootInactiveUser, true)); assertThat(underTest.selectByLogin(session, nonRootInactiveUser).isRoot()).isFalse(); // create inactive root user UserDto rootUser = insertActiveUser(); commit(() -> underTest.setRoot(session, rootUser.getLogin(), true)); rootUser.setActive(false); commit(() -> underTest.update(session, rootUser)); UserDto inactiveRootUser = underTest.selectByLogin(session, rootUser.getLogin()); assertThat(inactiveRootUser.isRoot()).isTrue(); assertThat(inactiveRootUser.isActive()).isFalse(); commit(() -> underTest.setRoot(session, inactiveRootUser.getLogin(), false)); assertThat(underTest.selectByLogin(session, inactiveRootUser.getLogin()).isRoot()).isTrue(); }
@Test public void execute_has_no_effect_when_user_is_already_root() { UserDto otherUser = UserTesting.newUserDto(); userDao.insert(dbSession, otherUser); userDao.insert(dbSession, UserTesting.newUserDto(SOME_LOGIN, "name", "email")); userDao.setRoot(dbSession, SOME_LOGIN, true); dbSession.commit(); logInAsRoot(); executeRequest(SOME_LOGIN); assertThat(userDao.selectByLogin(dbSession, SOME_LOGIN).isRoot()).isTrue(); assertThat(userDao.selectByLogin(dbSession, otherUser.getLogin()).isRoot()).isFalse(); }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkIsRoot(); String login = request.mandatoryParam(PARAM_LOGIN); try (DbSession dbSession = dbClient.openSession(false)) { UserDto userDto = dbClient.userDao().selectByLogin(dbSession, login); if (userDto == null || !userDto.isActive()) { throw new NotFoundException(format("User with login '%s' not found", login)); } checkRequest(dbClient.userDao().countRootUsersButLogin(dbSession, login) > 0, "Last root can't be unset"); if (userDto.isRoot()) { dbClient.userDao().setRoot(dbSession, login, false); dbSession.commit(); } } response.noContent(); }
.setHomepageParameter("OB1")); UserDto user2 = db.users().insertUser(); underTest.setRoot(session, user2.getLogin(), true);
public UserDto makeRoot(UserDto userDto) { dbClient.userDao().setRoot(db.getSession(), userDto.getLogin(), true); db.commit(); return dbClient.userDao().selectByLogin(db.getSession(), userDto.getLogin()); }
public UserDto makeNotRoot(UserDto userDto) { dbClient.userDao().setRoot(db.getSession(), userDto.getLogin(), false); db.commit(); return dbClient.userDao().selectByLogin(db.getSession(), userDto.getLogin()); }
@Test public void execute_returns_root_users_sorted_by_name() { logInAsRoot(); userDao.insert(dbSession, UserTesting.newUserDto().setName("ddd")); UserDto root1 = userDao.insert(dbSession, UserTesting.newUserDto().setName("ccc")); userDao.setRoot(dbSession, root1.getLogin(), true); UserDto root2 = userDao.insert(dbSession, UserTesting.newUserDto().setName("bbb")); userDao.setRoot(dbSession, root2.getLogin(), true); userDao.insert(dbSession, UserTesting.newUserDto().setName("aaa")); dbSession.commit(); assertThat(executeRequest()) .extracting(Roots.RootContent::getName) .containsExactly("bbb", "ccc"); }
@Test public void test_response_example() { logInAsRoot(); UserDto user = UserTesting.newUserDto().setLogin("daniel").setName("Daniel").setEmail("daniel@corp.com"); UserDto rootDto = userDao.insert(dbSession, user); userDao.setRoot(dbSession, rootDto.getLogin(), true); dbSession.commit(); TestResponse response = wsTester.newRequest().setMediaType(MediaTypes.JSON).execute(); assertJson(response.getInput()).isSimilarTo(wsTester.getDef().responseExampleAsString()); }
private void flagCurrentUserAsRoot(DbSession dbSession) { dbClient.userDao().setRoot(dbSession, requireNonNull(userSession.getLogin()), true); }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkIsRoot(); String login = request.mandatoryParam(PARAM_LOGIN); try (DbSession dbSession = dbClient.openSession(false)) { UserDto userDto = dbClient.userDao().selectByLogin(dbSession, login); if (userDto == null || !userDto.isActive()) { throw new NotFoundException(format("User with login '%s' not found", login)); } if (!userDto.isRoot()) { dbClient.userDao().setRoot(dbSession, login, true); dbSession.commit(); } } response.noContent(); }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkIsRoot(); String login = request.mandatoryParam(PARAM_LOGIN); try (DbSession dbSession = dbClient.openSession(false)) { UserDto userDto = dbClient.userDao().selectByLogin(dbSession, login); if (userDto == null || !userDto.isActive()) { throw new NotFoundException(format("User with login '%s' not found", login)); } checkRequest(dbClient.userDao().countRootUsersButLogin(dbSession, login) > 0, "Last root can't be unset"); if (userDto.isRoot()) { dbClient.userDao().setRoot(dbSession, login, false); dbSession.commit(); } } response.noContent(); }