]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8134 remove RoleDao#deleteGroupRolesByResourceId()
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 12 Oct 2016 22:20:20 +0000 (00:20 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 13 Oct 2016 10:18:42 +0000 (12:18 +0200)
Replaced by GroupPermissionDao#deleteByRootComponentId()

14 files changed:
sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionDao.java
sonar-db/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java
sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java
sonar-db/src/main/java/org/sonar/db/user/RoleDao.java
sonar-db/src/main/java/org/sonar/db/user/RoleMapper.java
sonar-db/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
sonar-db/src/main/resources/org/sonar/db/user/RoleMapper.xml
sonar-db/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
sonar-db/src/test/java/org/sonar/db/user/RoleDaoTest.java
sonar-db/src/test/java/org/sonar/db/user/RoleMapperTest.java
sonar-db/src/test/resources/org/sonar/db/user/RoleDaoTest/should_remove_all_permissions-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/user/RoleDaoTest/should_remove_all_permissions.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/user/RoleMapperTest/deleteRolesByResourceId-result.xml [deleted file]
sonar-db/src/test/resources/org/sonar/db/user/RoleMapperTest/deleteRolesByResourceId.xml [deleted file]

index 653dbf2c111aa9bd8b347416b57a40e50f320cf6..37e375b4b46fc1d3007628b3af36ee2dd0f5298e 100644 (file)
@@ -113,8 +113,14 @@ public class GroupPermissionDao implements Dao {
     mapper(dbSession).insert(dto);
   }
 
+  /**
+   * Delete all the permissions associated to a root component (project)
+   */
+  public void deleteByRootComponentId(DbSession dbSession, long rootComponentId) {
+    mapper(dbSession).deleteByRootComponentId(rootComponentId);
+  }
+
   private static GroupPermissionMapper mapper(DbSession session) {
     return session.getMapper(GroupPermissionMapper.class);
   }
-
 }
index 331aa4097872bf0a6f3341a828a83fbd014a83ee..ca005bcc6177c22136ef1a7b03a7b534f4e03866 100644 (file)
@@ -59,4 +59,6 @@ public interface GroupPermissionMapper {
   List<String> selectAnyonePermissions(@Nullable @Param("projectId") Long projectId);
 
   void insert(GroupPermissionDto dto);
+
+  void deleteByRootComponentId(@Param("rootComponentId") long componentId);
 }
index 56700dac063698ca405d0fa2e9e7d07d6cec9e29..53b335642965dc0e3fc3224bbe19ff3250b28559 100644 (file)
@@ -81,7 +81,7 @@ public class PermissionRepository {
   private void applyPermissionTemplate(DbSession session, String templateUuid, ComponentDto project, @Nullable Long currentUserId) {
     PermissionTemplate template = dbClient.permissionTemplateDao().selectPermissionTemplateWithPermissions(session, templateUuid);
     updateProjectAuthorizationDate(session, project.getId());
-    dbClient.roleDao().deleteGroupRolesByResourceId(session, project.getId());
+    dbClient.groupPermissionDao().deleteByRootComponentId(session, project.getId());
     dbClient.userPermissionDao().delete(session, null, project.uuid(), null);
 
     List<PermissionTemplateUserDto> usersPermissions = template.getUserPermissions();
index 309ec6371d5f4562bf42da135bb07ad69bf64e53..04d8e82bde2dbabd0cd364e435c21f7ef85a0de0 100644 (file)
@@ -53,10 +53,6 @@ public class RoleDao implements Dao {
     mapper(session).deleteGroupRole(groupRole);
   }
 
-  public void deleteGroupRolesByResourceId(DbSession session, long projectId) {
-    mapper(session).deleteGroupRolesByResourceId(projectId);
-  }
-
   private static int countResourceGroupRoles(DbSession session, Long resourceId) {
     return mapper(session).countResourceGroupRoles(resourceId);
   }
index 68342b045f4749730957d0ee08d076db6f9e2316..783514c5fafa30ce588d57949e10f076c9389f58 100644 (file)
@@ -38,8 +38,6 @@ public interface RoleMapper {
 
   void deleteGroupRole(GroupPermissionDto dto);
 
-  void deleteGroupRolesByResourceId(long projectId);
-
   int countResourceGroupRoles(Long resourceId);
 
   int countResourceUserRoles(long resourceId);
index 0cfd9472ff3b82b4d3bc7b98076237140a7d8ba2..065111f7bfed1ddd5db055d7652fb6a5e43e6e08 100644 (file)
     #{role,jdbcType=VARCHAR}
     )
   </insert>
+
+  <delete id="deleteByRootComponentId" parameterType="long">
+    delete from group_roles
+    where resource_id=#{rootComponentId,jdbcType=BIGINT}
+  </delete>
 </mapper>
index 9cd60e47a56608ecfcf05570e2ebad28f1a56fe1..27a020c8dce1e9402b85c8c50c7cf3d03963bd0d 100644 (file)
     </choose>
   </delete>
 
-  <delete id="deleteGroupRolesByResourceId" parameterType="long">
-    delete from group_roles where resource_id=#{id}
-  </delete>
-
   <select id="countResourceUserRoles" parameterType="long" resultType="int">
     SELECT count(1)
     FROM user_roles WHERE resource_id=#{id}
index a74c5ab974fa169693f17b4bd2c64e69db8f1ed7..b1b4cc869f7fa38e7f82204c40d75bf2b1681766 100644 (file)
@@ -315,4 +315,22 @@ public class GroupPermissionDaoTest {
     assertThat(underTest.selectAnyonePermissions(dbSession, project.getId())).containsOnly("perm4");
     assertThat(underTest.selectAnyonePermissions(dbSession, UNKNOWN_PROJECT_ID)).isEmpty();
   }
+
+  @Test
+  public void deleteByRootComponentId() {
+    GroupDto group1 = db.users().insertGroup(newGroupDto());
+    GroupDto group2 = db.users().insertGroup(newGroupDto());
+    ComponentDto project1 = db.components().insertProject();
+    ComponentDto project2 = db.components().insertProject();
+    db.users().insertPermissionOnGroup(group1, "perm1");
+    db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
+    db.users().insertProjectPermissionOnAnyone("perm3", project1);
+    db.users().insertProjectPermissionOnGroup(group2, "perm4", project2);
+
+    underTest.deleteByRootComponentId(dbSession, project1.getId());
+    dbSession.commit();
+
+    assertThat(db.countSql("select count(id) from group_roles where resource_id=" + project1.getId())).isEqualTo(0);
+    assertThat(db.countRowsOfTable("group_roles")).isEqualTo(2);
+  }
 }
index bba3a58841652a38d581805a91565d2cc6178cb8..e092e46465a43e104de33b82a95b209865fcc7e8 100644 (file)
@@ -158,21 +158,6 @@ public class RoleDaoTest {
     assertThat(underTest.countComponentPermissions(db.getSession(), 123L)).isEqualTo(2);
   }
 
-  @Test
-  public void should_remove_group_permissions_on_project() {
-    db.prepareDbUnit(getClass(), "should_remove_all_permissions.xml");
-
-    assertThat(underTest.selectGroupPermissions(db.getSession(), "devs", 123L)).hasSize(1);
-    assertThat(underTest.selectGroupPermissions(db.getSession(), "other", 123L)).isEmpty();
-
-    underTest.deleteGroupRolesByResourceId(db.getSession(), 123L);
-    db.getSession().commit();
-
-    db.assertDbUnitTable(getClass(), "should_remove_all_permissions-result.xml", "group_roles", "group_id", "resource_id", "role");
-
-    assertThat(underTest.selectGroupPermissions(db.getSession(), "devs", 123L)).isEmpty();
-  }
-
   @Test
   public void countUserPermissions() {
     db.users().insertProjectPermissionOnUser(user1, GlobalPermissions.SYSTEM_ADMIN, project1);
index 94f404282e1d5a90bbb4e048fed953c3ed33d37d..50d7555047c60b1e97a60eed1a1dd3c3db016985 100644 (file)
@@ -40,15 +40,4 @@ public class RoleMapperTest {
     assertThat(mapper.countResourceUserRoles(123L)).isEqualTo(1);
   }
 
-  @Test
-  public void delete_roles_by_resource_id() {
-    dbTester.prepareDbUnit(getClass(), "deleteRolesByResourceId.xml");
-
-    RoleMapper mapper = dbTester.getSession().getMapper(RoleMapper.class);
-    mapper.deleteGroupRolesByResourceId(123L);
-    dbTester.getSession().commit();
-
-    dbTester.assertDbUnit(getClass(), "deleteRolesByResourceId-result.xml", "group_roles");
-  }
-
 }
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/RoleDaoTest/should_remove_all_permissions-result.xml b/sonar-db/src/test/resources/org/sonar/db/user/RoleDaoTest/should_remove_all_permissions-result.xml
deleted file mode 100644 (file)
index 77964cd..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<dataset>
-
-  <users id="200"
-         login="dave.loper"
-         name="Dave Loper"
-         email="dave.loper@company.net"
-         active="[true]"
-         is_root="[false]"/>
-
-  <groups id="100"
-          name="devs"
-          organization_uuid="org1"/>
-
-  <user_roles/>
-
-  <group_roles/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/RoleDaoTest/should_remove_all_permissions.xml b/sonar-db/src/test/resources/org/sonar/db/user/RoleDaoTest/should_remove_all_permissions.xml
deleted file mode 100644 (file)
index 3c91825..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<dataset>
-
-  <users id="200"
-         login="dave.loper"
-         name="Dave Loper"
-         email="dave.loper@company.net"
-         active="[true]"
-         is_root="[false]"/>
-
-  <groups id="100"
-          name="devs"
-          organization_uuid="org1"/>
-
-  <user_roles id="1"
-              user_id="200"
-              resource_id="123"
-              role="user"
-              organization_uuid="org1"/>
-
-  <group_roles id="1"
-               group_id="100"
-               resource_id="123"
-               role="codeviewer"
-               organization_uuid="org1"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/RoleMapperTest/deleteRolesByResourceId-result.xml b/sonar-db/src/test/resources/org/sonar/db/user/RoleMapperTest/deleteRolesByResourceId-result.xml
deleted file mode 100644 (file)
index 7575e3f..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<dataset>
-  <groups id="100"
-          name="sonar-administrators"
-          organization_uuid="org1"/>
-  <groups id="101"
-          name="sonar-users"
-          organization_uuid="org1"/>
-  <users id="200"
-         login="marius"
-         name="Marius"
-         email="[null]"
-         active="[true]"
-         is_root="[false]"/>
-
-  <!--<group_roles id="1" group_id="100" resource_id="123" role="admin"/>-->
-  <!--<group_roles id="2" group_id="[null]" resource_id="123" role="user"/>-->
-  <!--<user_roles id="1" user_id="200" resource_id="123" role="codeviewer"/>-->
-
-  <!-- other resource -->
-  <group_roles id="3"
-               group_id="101"
-               resource_id="999"
-               role="codeviewer"
-               organization_uuid="org1"/>
-  <user_roles id="2"
-              user_id="200"
-              resource_id="999"
-              role="codeviewer"
-              organization_uuid="org1"/>
-
-</dataset>
diff --git a/sonar-db/src/test/resources/org/sonar/db/user/RoleMapperTest/deleteRolesByResourceId.xml b/sonar-db/src/test/resources/org/sonar/db/user/RoleMapperTest/deleteRolesByResourceId.xml
deleted file mode 100644 (file)
index c0e3567..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-<dataset>
-  <groups id="100"
-          name="sonar-administrators"
-          organization_uuid="org1"/>
-  <groups id="101"
-          name="sonar-users"
-          organization_uuid="org1"/>
-  <users id="200"
-         login="marius"
-         name="Marius"
-         email="[null]"
-         active="[true]"
-         is_root="[false]"/>
-
-  <group_roles id="1"
-               group_id="100"
-               resource_id="123"
-               role="admin"
-               organization_uuid="org1"/>
-  <group_roles id="2"
-               group_id="[null]"
-               resource_id="123"
-               role="user"
-               organization_uuid="org1"/>
-  <user_roles id="1"
-              user_id="200"
-              resource_id="123"
-              role="codeviewer"
-              organization_uuid="org1"/>
-
-  <!-- other resource -->
-  <group_roles id="3"
-               group_id="101"
-               resource_id="999"
-               role="codeviewer"
-               organization_uuid="org1"/>
-  <user_roles id="2"
-              user_id="200"
-              resource_id="999"
-              role="codeviewer"
-              organization_uuid="org1"/>
-
-</dataset>