@@ -76,6 +76,10 @@ public class QProfileEditGroupsDao implements Dao { | |||
executeLargeUpdates(qProfiles.stream().map(QProfileDto::getKee).collect(toList()), p -> mapper(dbSession).deleteByQProfiles(p)); | |||
} | |||
public void deleteByGroup(DbSession dbSession, GroupDto group) { | |||
mapper(dbSession).deleteByGroup(group.getId()); | |||
} | |||
private static QProfileEditGroupsMapper mapper(DbSession dbSession) { | |||
return dbSession.getMapper(QProfileEditGroupsMapper.class); | |||
} |
@@ -40,4 +40,6 @@ public interface QProfileEditGroupsMapper { | |||
void deleteByQProfiles(@Param("qProfileUuids") Collection<String> qProfileUuids); | |||
void deleteByGroup(@Param("groupId") int groupId); | |||
} |
@@ -109,5 +109,10 @@ | |||
where qprofile_uuid in <foreach collection="qProfileUuids" open="(" close=")" item="qProfileUuid" separator=",">#{qProfileUuid, jdbcType=VARCHAR}</foreach> | |||
</delete> | |||
<delete id="deleteByGroup" parameterType="map"> | |||
delete from qprofile_edit_groups | |||
where group_id = #{groupId, jdbcType=INTEGER} | |||
</delete> | |||
</mapper> | |||
@@ -277,4 +277,27 @@ public class QProfileEditGroupsDaoTest { | |||
assertThat(underTest.exists(db.getSession(), anotherProfile, group1)).isTrue(); | |||
} | |||
@Test | |||
public void deleteByGroup() { | |||
OrganizationDto organization = db.organizations().insert(); | |||
OrganizationDto anotherOrganization = db.organizations().insert(); | |||
QProfileDto profile1 = db.qualityProfiles().insert(organization); | |||
QProfileDto profile2 = db.qualityProfiles().insert(organization); | |||
QProfileDto profile3 = db.qualityProfiles().insert(organization); | |||
QProfileDto anotherProfile = db.qualityProfiles().insert(anotherOrganization); | |||
GroupDto group1 = db.users().insertGroup(organization); | |||
GroupDto group2 = db.users().insertGroup(organization); | |||
db.qualityProfiles().addGroupPermission(profile1, group1); | |||
db.qualityProfiles().addGroupPermission(profile2, group2); | |||
db.qualityProfiles().addGroupPermission(profile3, group1); | |||
db.qualityProfiles().addGroupPermission(anotherProfile, group1); | |||
underTest.deleteByGroup(db.getSession(), group1); | |||
assertThat(underTest.exists(db.getSession(), profile1, group1)).isFalse(); | |||
assertThat(underTest.exists(db.getSession(), profile2, group2)).isTrue(); | |||
assertThat(underTest.exists(db.getSession(), profile3, group1)).isFalse(); | |||
assertThat(underTest.exists(db.getSession(), anotherProfile, group1)).isFalse(); | |||
} | |||
} |
@@ -72,6 +72,7 @@ public class DeleteAction implements UserGroupsWsAction { | |||
removeGroupPermissions(dbSession, group); | |||
removeFromPermissionTemplates(dbSession, group); | |||
removeGroupMembers(dbSession, group); | |||
dbClient.qProfileEditGroupsDao().deleteByGroup(dbSession, group); | |||
dbClient.groupDao().deleteById(dbSession, group.getId()); | |||
dbSession.commit(); |
@@ -31,6 +31,7 @@ import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.permission.template.PermissionTemplateDto; | |||
import org.sonar.db.permission.template.PermissionTemplateTesting; | |||
import org.sonar.db.qualityprofile.QProfileDto; | |||
import org.sonar.db.user.GroupDto; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
@@ -184,6 +185,22 @@ public class DeleteActionTest { | |||
assertThat(db.countRowsOfTable("perm_templates_groups")).isEqualTo(0); | |||
} | |||
@Test | |||
public void delete_qprofile_permissions() throws Exception { | |||
addAdminToDefaultOrganization(); | |||
insertDefaultGroupOnDefaultOrganization(); | |||
GroupDto group = db.users().insertGroup(); | |||
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization()); | |||
db.qualityProfiles().addGroupPermission(profile, group); | |||
loginAsAdminOnDefaultOrganization(); | |||
newRequest() | |||
.setParam("id", group.getId().toString()) | |||
.execute(); | |||
assertThat(db.countRowsOfTable("qprofile_edit_groups")).isZero(); | |||
} | |||
@Test | |||
public void fail_if_id_does_not_exist() throws Exception { | |||
addAdminToDefaultOrganization(); |