aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-09-27 18:29:22 +0200
committerStas Vilchik <stas.vilchik@sonarsource.com>2017-10-02 17:18:15 +0200
commitcf6b9cb7a653e875f693a8364642411b46d38d95 (patch)
tree03479219609ccd9e96a44336671d54e0d2db0531 /server/sonar-db-dao
parentb21a14010c4941746cffb5de4296ec99a4ebf981 (diff)
downloadsonarqube-cf6b9cb7a653e875f693a8364642411b46d38d95.tar.gz
sonarqube-cf6b9cb7a653e875f693a8364642411b46d38d95.zip
SONAR-1330 Purge edit permissions when removing group
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java23
4 files changed, 34 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDao.java
index c390e7afee0..ecb6b5355ab 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsDao.java
@@ -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);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.java
index 561b0f85085..668a0a4999c 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.java
@@ -40,4 +40,6 @@ public interface QProfileEditGroupsMapper {
void deleteByQProfiles(@Param("qProfileUuids") Collection<String> qProfileUuids);
+ void deleteByGroup(@Param("groupId") int groupId);
+
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml
index 0ce45bd4ee7..9a023f45047 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditGroupsMapper.xml
@@ -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>
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java
index 82c2f91f882..003cf80e236 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditGroupsDaoTest.java
@@ -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();
+ }
+
}