]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15443 - Removing a group removes QG group permission
authorBelen Pruvost <belen.pruvost@sonarsource.com>
Mon, 18 Oct 2021 15:34:33 +0000 (17:34 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 22 Oct 2021 20:03:28 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateGroupPermissionsDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateGroupPermissionsMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateGroupPermissionsMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateGroupPermissionsDaoTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/DeleteAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java

index e3c387411116101c339412927ef9185ede789969..d042feb2f6bc6afd5c0ff8a47a01f0e4dfe653e0 100644 (file)
@@ -69,6 +69,10 @@ public class QualityGateGroupPermissionsDao implements Dao {
     return mapper(dbSession).countByQuery(query);
   }
 
+  public void deleteByGroup(DbSession dbSession, GroupDto group) {
+    mapper(dbSession).deleteByGroup(group.getUuid());
+  }
+
   public void deleteByQualityGateAndGroup(DbSession dbSession, QualityGateDto qualityGate, GroupDto group) {
     mapper(dbSession).delete(qualityGate.getUuid(), group.getUuid());
   }
index eef27294b4239354d4b009c65c98cd4682e1c6f2..198070f41c7da8b9e60671e345390d3412aeb33d 100644 (file)
@@ -37,6 +37,8 @@ public interface QualityGateGroupPermissionsMapper {
 
   int countByQuery(@Param("query") SearchPermissionQuery query);
 
+  void deleteByGroup(@Param("groupUuid") String groupUuid);
+
   void delete(@Param("qualityGateUuid") String qualityGateUuid, @Param("groupUuid") String groupUuid);
 
 }
index 95e7ad615c1ec53cf31471ae67965256b8f6332f..7402fb0e174d5f155e87add26b014b2e3d54b237 100644 (file)
     and group_uuid = #{groupUuid, jdbcType=VARCHAR}
   </delete>
 
+  <delete id="deleteByGroup" parameterType="map">
+    delete from qgate_group_permissions
+    where group_uuid = #{groupUuid, jdbcType=VARCHAR}
+  </delete>
+
 </mapper>
index cd8d5894106572d464f4a335efe145419ac80993..6af356fa2657e28906594e957d7fc191dec9f956 100644 (file)
@@ -202,6 +202,25 @@ public class QualityGateGroupPermissionsDaoTest {
       .containsExactly(group1.getUuid(), group2.getUuid(), group3.getUuid());
   }
 
+  @Test
+  public void deleteByGroup() {
+    QualityGateDto qualityGateDto1 = insertQualityGate();
+    QualityGateDto qualityGateDto2 = insertQualityGate();
+    QualityGateDto qualityGateDto3 = insertQualityGate();
+
+    GroupDto group1 = dbTester.users().insertGroup();
+    GroupDto group2 = dbTester.users().insertGroup();
+    dbTester.qualityGates().addGroupPermission(qualityGateDto1, group1);
+    dbTester.qualityGates().addGroupPermission(qualityGateDto2, group2);
+    dbTester.qualityGates().addGroupPermission(qualityGateDto3, group1);
+
+    underTest.deleteByGroup(dbSession, group1);
+
+    assertThat(underTest.exists(dbSession, qualityGateDto1, group1)).isFalse();
+    assertThat(underTest.exists(dbSession, qualityGateDto2, group2)).isTrue();
+    assertThat(underTest.exists(dbSession, qualityGateDto3, group1)).isFalse();
+  }
+
   @Test
   public void deleteByQProfileAndGroup() {
     QualityGateDto qualityGateDto = insertQualityGate();
index a7b5891ad159266e588bcbcc6c32fd9df9a90b58..2b1f6fe506e3869dc9a27276ddd6f473f074028e 100644 (file)
@@ -76,6 +76,7 @@ public class DeleteAction implements UserGroupsWsAction {
       removeFromPermissionTemplates(dbSession, group);
       removeGroupMembers(dbSession, group);
       dbClient.qProfileEditGroupsDao().deleteByGroup(dbSession, group);
+      dbClient.qualityGateGroupPermissionsDao().deleteByGroup(dbSession, group);
       dbClient.groupDao().deleteByUuid(dbSession, group.getUuid(), group.getName());
 
       dbSession.commit();
index c7d07c60ff42a253afcad78d3584354478447375..77ef3b3f027cc71c6f6795b623a3a16aa4e0a2c0 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.permission.template.PermissionTemplateTesting;
+import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.db.qualityprofile.QProfileDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
@@ -182,6 +183,22 @@ public class DeleteActionTest {
     assertThat(db.countRowsOfTable("qprofile_edit_groups")).isZero();
   }
 
+  @Test
+  public void delete_qgate_permissions() {
+    addAdmin();
+    insertDefaultGroup();
+    GroupDto group = db.users().insertGroup();
+    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
+    db.qualityGates().addGroupPermission(qualityGate, group);
+    loginAsAdmin();
+
+    newRequest()
+      .setParam("id", group.getUuid())
+      .execute();
+
+    assertThat(db.countRowsOfTable("qgate_group_permissions")).isZero();
+  }
+
   @Test
   public void fail_if_id_does_not_exist() {
     addAdmin();