aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorZipeng WU <zipeng.wu@sonarsource.com>2021-10-19 17:52:51 +0200
committersonartech <sonartech@sonarsource.com>2021-10-22 20:03:28 +0000
commit090fd5e9cd9bd868256d83217d82d87e0f8ca2a4 (patch)
tree40a86c7e8044b13094c679da90af9995e3f9feb8 /server/sonar-db-dao
parentd64a04c89a6c31839faac5b78a556cb4e3fed5ee (diff)
downloadsonarqube-090fd5e9cd9bd868256d83217d82d87e0f8ca2a4.tar.gz
sonarqube-090fd5e9cd9bd868256d83217d82d87e0f8ca2a4.zip
SONAR-15541 Create api/qualitygates/remove_user service
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.xml6
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDaoTest.java13
4 files changed, 25 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDao.java
index 5d383b5f5b8..18c9440a847 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDao.java
@@ -64,6 +64,10 @@ public class QualityGateUserPermissionsDao implements Dao {
return mapper(dbSession).countByQuery(query);
}
+ public void deleteByQualityGateAndUser(DbSession dbSession, QualityGateDto qualityGate, UserDto user) {
+ mapper(dbSession).delete(qualityGate.getUuid(), user.getUuid());
+ }
+
public void deleteByUser(DbSession dbSession, UserDto user) {
mapper(dbSession).deleteByUser(user.getUuid());
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.java
index 8f3a7c8e268..5edf1c3aa13 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.java
@@ -35,6 +35,8 @@ public interface QualityGateUserPermissionsMapper {
int countByQuery(@Param("query") SearchPermissionQuery query);
+ void delete(@Param("qualityGateUuid") String qualityGateUuid, @Param("userUuid") String userUuid);
+
void deleteByUser(@Param("userUuid") String userUuid);
void deleteByQualityGate(@Param("qualityGateUuid") String qualityGateUuid);
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.xml
index 628a828f1f7..149fc766cfb 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateUserPermissionsMapper.xml
@@ -92,6 +92,12 @@
</where>
</sql>
+ <delete id="delete">
+ delete from qgate_user_permissions
+ where quality_gate_uuid = #{qualityGateUuid}
+ and user_uuid = #{userUuid}
+ </delete>
+
<delete id="deleteByUser">
delete from qgate_user_permissions
where user_uuid = #{userUuid}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDaoTest.java
index 048be73e898..0c956d9bdca 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateUserPermissionsDaoTest.java
@@ -208,6 +208,19 @@ public class QualityGateUserPermissionsDaoTest {
}
@Test
+ public void deleteByQualityGateAndUser() {
+ QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+ UserDto user = db.users().insertUser();
+ db.qualityGates().addUserPermission(qualityGate, user);
+
+ assertThat(underTest.exists(dbSession, qualityGate, user)).isTrue();
+
+ underTest.deleteByQualityGateAndUser(dbSession, qualityGate, user);
+
+ assertThat(underTest.exists(dbSession, qualityGate, user)).isFalse();
+ }
+
+ @Test
public void deleteByUser() {
QualityGateDto qualityGateDto1 = db.qualityGates().insertQualityGate();
QualityGateDto qualityGateDto2 = db.qualityGates().insertQualityGate();