From b2ab634816dce76926da525a482383ab5cd6f4dc Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 13 Oct 2016 00:54:42 +0200 Subject: SONAR-8134 remove RoleDao#deleteGroupRole() replaced by GroupPermissionDao#delete() --- .../sonar/db/permission/GroupPermissionDao.java | 18 ++++++ .../sonar/db/permission/GroupPermissionMapper.java | 3 + .../sonar/db/permission/PermissionRepository.java | 9 --- .../src/main/java/org/sonar/db/user/RoleDao.java | 9 --- .../main/java/org/sonar/db/user/RoleMapper.java | 3 - .../sonar/db/permission/GroupPermissionMapper.xml | 25 ++++++++ .../resources/org/sonar/db/user/RoleMapper.xml | 23 -------- .../db/permission/GroupPermissionDaoTest.java | 68 ++++++++++++++++++++++ .../db/permission/PermissionRepositoryTest.java | 12 ---- .../test/java/org/sonar/db/user/RoleDaoTest.java | 25 -------- .../test/java/org/sonar/db/user/UserDbTester.java | 8 +++ .../should_delete_group_permission-result.xml | 30 ---------- .../should_delete_group_permission.xml | 35 ----------- 13 files changed, 122 insertions(+), 146 deletions(-) delete mode 100644 sonar-db/src/test/resources/org/sonar/db/permission/PermissionRepositoryTest/should_delete_group_permission-result.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/permission/PermissionRepositoryTest/should_delete_group_permission.xml (limited to 'sonar-db') diff --git a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java index 37e375b4b46..c1685e39776 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java @@ -120,6 +120,24 @@ public class GroupPermissionDao implements Dao { mapper(dbSession).deleteByRootComponentId(rootComponentId); } + /** + * Delete a single permission. It can be: + * + * @param dbSession + * @param permission the kind of permission + * @param organizationUuid UUID of organization, even if parameter {@code groupId} is not null + * @param groupId if null, then anyone, else id of group + * @param rootComponentId if null, then global permission, else id of root component (project) + */ + public void delete(DbSession dbSession, String permission, String organizationUuid, @Nullable Long groupId, @Nullable Long rootComponentId) { + mapper(dbSession).delete(permission, organizationUuid, groupId, rootComponentId); + } + private static GroupPermissionMapper mapper(DbSession session) { return session.getMapper(GroupPermissionMapper.class); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java index ca005bcc617..5a8138776c9 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java @@ -61,4 +61,7 @@ public interface GroupPermissionMapper { void insert(GroupPermissionDto dto); void deleteByRootComponentId(@Param("rootComponentId") long componentId); + + void delete(@Param("permission") String permission, @Param("organizationUuid") String organizationUuid, + @Nullable @Param("groupId") Long groupId, @Nullable @Param("rootComponentId") Long rootComponentId); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java index 53b33564296..d909d0ff0fe 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java @@ -56,15 +56,6 @@ public class PermissionRepository { this.settings = settings; } - public void deleteGroupPermission(@Nullable Long resourceId, @Nullable Long groupId, String permission, DbSession session) { - GroupPermissionDto groupRole = new GroupPermissionDto() - .setRole(permission) - .setGroupId(groupId) - .setResourceId(resourceId); - updateProjectAuthorizationDate(session, resourceId); - dbClient.roleDao().deleteGroupRole(groupRole, session); - } - /** * For each modification of permission on a project, update the authorization_updated_at to help ES reindex only relevant changes */ diff --git a/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java b/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java index 04d8e82bde2..2eb62c0efc6 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java +++ b/sonar-db/src/main/java/org/sonar/db/user/RoleDao.java @@ -24,7 +24,6 @@ import javax.annotation.Nullable; import org.sonar.api.security.DefaultGroups; import org.sonar.db.Dao; import org.sonar.db.DbSession; -import org.sonar.db.permission.GroupPermissionDto; public class RoleDao implements Dao { @@ -45,14 +44,6 @@ public class RoleDao implements Dao { return session.getMapper(RoleMapper.class).selectGroupPermissions(groupName, resourceId, DefaultGroups.isAnyone(groupName)); } - /** - * @deprecated does not support organizations on anyone groups - */ - @Deprecated - public void deleteGroupRole(GroupPermissionDto groupRole, DbSession session) { - mapper(session).deleteGroupRole(groupRole); - } - private static int countResourceGroupRoles(DbSession session, Long resourceId) { return mapper(session).countResourceGroupRoles(resourceId); } diff --git a/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java b/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java index 783514c5faf..23d154d5cbe 100644 --- a/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java @@ -22,7 +22,6 @@ package org.sonar.db.user; import java.util.List; import javax.annotation.Nullable; import org.apache.ibatis.annotations.Param; -import org.sonar.db.permission.GroupPermissionDto; /** * @since 3.2 @@ -36,8 +35,6 @@ public interface RoleMapper { */ List selectGroupPermissions(@Param("groupName") String groupName, @Nullable @Param("resourceId") Long resourceId, @Param("isAnyOneGroup") Boolean isAnyOneGroup); - void deleteGroupRole(GroupPermissionDto dto); - int countResourceGroupRoles(Long resourceId); int countResourceUserRoles(long resourceId); diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml index 065111f7bfe..dff26a62a71 100644 --- a/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml @@ -168,4 +168,29 @@ delete from group_roles where resource_id=#{rootComponentId,jdbcType=BIGINT} + + + delete from group_roles + where + role=#{permission,jdbcType=VARCHAR} and + organization_uuid=#{organizationUuid,jdbcType=VARCHAR} and + + + resource_id=#{rootComponentId,jdbcType=BIGINT} + + + resource_id is null + + + and + + + group_id=#{groupId,jdbcType=BIGINT} + + + group_id is null + + + + diff --git a/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml b/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml index 27a020c8dce..0ac0d435512 100644 --- a/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml @@ -49,29 +49,6 @@ - - DELETE FROM group_roles - WHERE role=#{role} - AND - - - resource_id=#{resourceId} - - - resource_id IS NULL - - - AND - - - group_id=#{groupId} - - - group_id IS NULL - - - -