diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-06-26 07:59:29 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-06-26 07:59:29 +0200 |
commit | 518e18bf793fa576e09bce11f62e62f45e0c2f71 (patch) | |
tree | 2cc028c8ba5f21d53a723e68b7135ffbd021bd38 /sonar-core/src/main | |
parent | 2288f38f78b8e065ab34927311f90016d3897a71 (diff) | |
download | sonarqube-518e18bf793fa576e09bce11f62e62f45e0c2f71.tar.gz sonarqube-518e18bf793fa576e09bce11f62e62f45e0c2f71.zip |
SONAR-4411 Java implementation of user deactivation
Diffstat (limited to 'sonar-core/src/main')
4 files changed, 86 insertions, 11 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/user/DefaultUserFinder.java b/sonar-core/src/main/java/org/sonar/core/user/DefaultUserFinder.java index 2ddfb1a76c9..929fb60b112 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/DefaultUserFinder.java +++ b/sonar-core/src/main/java/org/sonar/core/user/DefaultUserFinder.java @@ -42,7 +42,7 @@ public class DefaultUserFinder implements UserFinder { @Override @CheckForNull public User findByLogin(String login) { - UserDto dto = userDao.selectUserByLogin(login); + UserDto dto = userDao.selectActiveUserByLogin(login); return dto != null ? dto.toUser() : null; } diff --git a/sonar-core/src/main/java/org/sonar/core/user/UserDao.java b/sonar-core/src/main/java/org/sonar/core/user/UserDao.java index 42a28e35a5d..6a2ce6a499b 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/UserDao.java +++ b/sonar-core/src/main/java/org/sonar/core/user/UserDao.java @@ -44,7 +44,7 @@ public class UserDao { * @return the user, null if user not found */ @CheckForNull - public UserDto selectUserByLogin(String login) { + public UserDto selectActiveUserByLogin(String login) { SqlSession session = mybatis.openSession(); try { UserMapper mapper = session.getMapper(UserMapper.class); @@ -82,6 +82,37 @@ public class UserDao { } /** + * Deactivate a user and drops all his preferences. + * @return false if the user does not exist, true if the existing user has been deactivated + */ + public boolean deactivateUserByLogin(String login) { + SqlSession session = mybatis.openSession(); + try { + UserMapper mapper = session.getMapper(UserMapper.class); + UserDto dto = mapper.selectUserByLogin(login); + if (dto == null) { + return false; + } + + mapper.removeUserFromGroups(dto.getId()); + mapper.deleteUserActiveDashboards(dto.getId()); + mapper.deleteUserDashboards(dto.getId()); + mapper.deleteUserIssueFilters(dto.getLogin()); + mapper.deleteUserIssueFilterFavourites(dto.getLogin()); + mapper.deleteUserMeasureFilters(dto.getId()); + mapper.deleteUserMeasureFilterFavourites(dto.getId()); + mapper.deleteUserProperties(dto.getId()); + mapper.deleteUserRoles(dto.getId()); + mapper.deactivateUser(dto.getId()); + session.commit(); + return true; + + } finally { + MyBatis.closeQuietly(session); + } + } + + /** * Search for group by name. * * @return the group, null if group not found diff --git a/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java b/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java index 74b5e08e9a7..8678b52d363 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/user/UserMapper.java @@ -25,9 +25,6 @@ import org.sonar.api.user.UserQuery; import javax.annotation.CheckForNull; import java.util.List; -/** - * @since 3.2 - */ public interface UserMapper { /** @@ -36,17 +33,21 @@ public interface UserMapper { @CheckForNull UserDto selectUserByLogin(String login); - /** - * @since 3.6 - */ List<UserDto> selectUsersByLogins(@Param("logins") List<String> logins); - /** - * @since 3.6 - */ List<UserDto> selectUsers(UserQuery query); @CheckForNull GroupDto selectGroupByName(String name); + void removeUserFromGroups(long userId); + void deleteUserActiveDashboards(long userId); + void deleteUserDashboards(long userId); + void deleteUserIssueFilters(String login); + void deleteUserIssueFilterFavourites(String login); + void deleteUserMeasureFilters(long userId); + void deleteUserMeasureFilterFavourites(long userId); + void deleteUserProperties(long userId); + void deleteUserRoles(long userId); + void deactivateUser(long userId); } diff --git a/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml b/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml index c662b2e03a9..3b5f9003cb6 100644 --- a/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/user/UserMapper.xml @@ -55,5 +55,48 @@ from groups where name=#{id} </select> + <delete id="removeUserFromGroups" parameterType="long"> + delete from groups_users where user_id=#{id} + </delete> + + <delete id="deleteUserRoles" parameterType="long"> + delete from user_roles where user_id=#{id} + </delete> + + <delete id="deleteUserProperties" parameterType="long"> + delete from properties where user_id=#{id} + </delete> + + <delete id="deleteUserDashboards" parameterType="long"> + delete from dashboards where user_id=#{id} + </delete> + + <delete id="deleteUserActiveDashboards" parameterType="long"> + delete from active_dashboards where user_id=#{id} + </delete> + + <delete id="" parameterType="long"> + delete from user_roles where user_id=#{id} + </delete> + + <delete id="deleteUserMeasureFilters" parameterType="long"> + delete from measure_filters where user_id=#{id} + </delete> + + <delete id="deleteUserMeasureFilterFavourites" parameterType="long"> + delete from measure_filter_favourites where user_id=#{id} + </delete> + + <delete id="deleteUserIssueFilters" parameterType="String"> + delete from issue_filters where user_login=#{id} + </delete> + + <delete id="deleteUserIssueFilterFavourites" parameterType="String"> + delete from issue_filter_favourites where user_login=#{id} + </delete> + + <update id="deactivateUser" parameterType="long"> + update users set active=${_false} where id=#{id} + </update> </mapper> |