diff options
author | Guillaume Jambet <guillaume.jambet@sonarsource.com> | 2017-12-19 16:16:28 +0100 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-01-02 10:38:10 +0100 |
commit | 983509731f3ec3ae861da229de7980160608d9bd (patch) | |
tree | a9f4f8608cf11f3ab52be35cebd408dd9c7678ee /server/sonar-db-dao/src | |
parent | 56c1dd13a73468dbbdc543f117876f9d574bc761 (diff) | |
download | sonarqube-983509731f3ec3ae861da229de7980160608d9bd.tar.gz sonarqube-983509731f3ec3ae861da229de7980160608d9bd.zip |
SONAR-10182 Clean homepage when deleting an organization
Diffstat (limited to 'server/sonar-db-dao/src')
4 files changed, 41 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java index 49a6bd9eff6..dcd27b2b809 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserDao.java @@ -35,6 +35,7 @@ import org.sonar.api.utils.System2; import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.RowNotFoundException; +import org.sonar.db.organization.OrganizationDto; import static org.sonar.db.DatabaseUtils.executeLargeInputs; import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput; @@ -121,6 +122,10 @@ public class UserDao implements Dao { mapper(dbSession).deactivateUser(user.getLogin(), system2.now()); } + public void cleanHomepage(DbSession dbSession, OrganizationDto organization) { + mapper(dbSession).clearHomepage("ORGANIZATION", organization.getUuid(), system2.now()); + } + @CheckForNull public UserDto selectByLogin(DbSession session, String login) { return mapper(session).selectByLogin(login); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java index a894164aa04..f9fddb00f99 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserMapper.java @@ -69,4 +69,5 @@ public interface UserMapper { void deactivateUser(@Param("login") String login, @Param("now") long now); + void clearHomepage(@Param("homepageType") String type, @Param("homepageValue") String value, @Param("now") long now); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml index 7e16d4ef582..db7e23a5b57 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml @@ -137,6 +137,16 @@ login = #{login, jdbcType=VARCHAR} </update> + <update id="clearHomepage" parameterType="map"> + update users set + homepage_type = null, + homepage_value = null, + updated_at = #{now, jdbcType=BIGINT} + where + homepage_type = #{homepageType, jdbcType=VARCHAR} + and homepage_value = #{homepageValue, jdbcType=VARCHAR} + </update> + <update id="setRoot"> update users set is_root = #{root, jdbcType=BOOLEAN}, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java index 448b17a4086..779a3bfdab2 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java @@ -34,6 +34,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.RowNotFoundException; +import org.sonar.db.organization.OrganizationDto; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; @@ -417,6 +418,30 @@ public class UserDaoTest { } @Test + public void clean_users_homepage() { + + UserDto userUnderTest = newUserDto().setHomepageType("ORGANIZATION").setHomepageValue("dummy-organization-UUID"); + underTest.insert(session, userUnderTest); + + UserDto untouchedUser = newUserDto().setHomepageType("ORGANIZATION").setHomepageValue("not-so-dummy-organization-UUID"); + underTest.insert(session, untouchedUser); + + session.commit(); + + underTest.cleanHomepage(session, new OrganizationDto().setUuid("dummy-organization-UUID")); + + UserDto userWithAHomepageReloaded = underTest.selectUserById(session, userUnderTest.getId()); + assertThat(userWithAHomepageReloaded.getUpdatedAt()).isEqualTo(NOW); + assertThat(userWithAHomepageReloaded.getHomepageType()).isNull(); + assertThat(userWithAHomepageReloaded.getHomepageValue()).isNull(); + + UserDto untouchedUserReloaded = underTest.selectUserById(session, untouchedUser.getId()); + assertThat(untouchedUserReloaded.getUpdatedAt()).isEqualTo(untouchedUser.getUpdatedAt()); + assertThat(untouchedUserReloaded.getHomepageType()).isEqualTo(untouchedUser.getHomepageType()); + assertThat(untouchedUserReloaded.getHomepageValue()).isEqualTo(untouchedUser.getHomepageValue()); + } + + @Test public void does_not_fail_to_deactivate_missing_user() { underTest.deactivateUser(session, UserTesting.newUserDto()); } |