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);
}
-
}
List<String> selectAnyonePermissions(@Nullable @Param("projectId") Long projectId);
void insert(GroupPermissionDto dto);
+
+ void deleteByRootComponentId(@Param("rootComponentId") long componentId);
}
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();
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);
}
void deleteGroupRole(GroupPermissionDto dto);
- void deleteGroupRolesByResourceId(long projectId);
-
int countResourceGroupRoles(Long resourceId);
int countResourceUserRoles(long resourceId);
#{role,jdbcType=VARCHAR}
)
</insert>
+
+ <delete id="deleteByRootComponentId" parameterType="long">
+ delete from group_roles
+ where resource_id=#{rootComponentId,jdbcType=BIGINT}
+ </delete>
</mapper>
</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}
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);
+ }
}
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);
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");
- }
-
}
+++ /dev/null
-<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>
+++ /dev/null
-<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>
+++ /dev/null
-<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>
+++ /dev/null
-<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>