]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10088 Prevent deleting default quality gate
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 28 Nov 2017 12:07:01 +0000 (13:07 +0100)
committerEric Hartmann <hartmann.eric@gmail.Com>
Mon, 4 Dec 2017 12:44:55 +0000 (13:44 +0100)
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java
server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/list-example.json
server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/show-example.json
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java
sonar-ws/src/main/protobuf/ws-qualitygates.proto

index e0cf37f5798cb19ff394333d4ee54323fb45cc90..b8e08178f04820f330e7b8967f7c478c6154d0c8 100644 (file)
@@ -60,7 +60,9 @@ public class QualityGatesWsSupport {
     boolean isQualityGateAdmin = isQualityGateAdmin();
     return Qualitygates.Actions.newBuilder()
       .setCopy(isQualityGateAdmin)
-      .setEdit(!isBuiltIn && isQualityGateAdmin)
+      .setRename(!isBuiltIn && isQualityGateAdmin)
+      .setManageConditions(!isBuiltIn && isQualityGateAdmin)
+      .setDelete(!isDefault && !isBuiltIn && isQualityGateAdmin)
       .setSetAsDefault(!isDefault && isQualityGateAdmin)
       .setAssociateProjects(!isDefault && isQualityGateAdmin)
       .build();
index 270dc554203d1dd4eee6c95c00f3cd5410c5c6b5..e29de1d7dfa92493b7621d9f4b39c2d705e5e084 100644 (file)
@@ -1,32 +1,36 @@
 {
   "qualitygates": [
     {
-      "id": 2,
+      "id": 8,
       "name": "Sonar way",
       "isDefault": true,
       "isBuiltIn": true,
       "actions": {
-        "edit": false,
+        "rename": false,
         "setAsDefault": false,
         "copy": true,
-        "associateProjects": false
+        "associateProjects": false,
+        "delete": false,
+        "manageConditions": false
       }
     },
     {
-      "id": 4,
+      "id": 9,
       "name": "Sonar way - Without Coverage",
       "isDefault": false,
       "isBuiltIn": false,
       "actions": {
-        "edit": true,
+        "rename": true,
         "setAsDefault": true,
         "copy": true,
-        "associateProjects": true
+        "associateProjects": true,
+        "delete": true,
+        "manageConditions": true
       }
     }
   ],
+  "default": 8,
   "actions": {
     "create": true
-  },
-  "default": 2
+  }
 }
index 6f0a06b2700858ad31ae349937cd44835dfc8f19..be112e2d24f484673f46397f1d8f3731f142a5b0 100644 (file)
@@ -1,26 +1,28 @@
 {
-  "id": 2,
+  "id": 5,
   "name": "My Quality Gate",
-  "isBuiltIn": false,
   "conditions": [
     {
-      "id": 9,
+      "id": 2,
       "metric": "blocker_violations",
       "op": "GT",
       "error": "0"
     },
     {
-      "id": 10,
+      "id": 3,
       "metric": "critical_violations",
       "period": 1,
       "op": "LT",
       "warning": "0"
     }
   ],
+  "isBuiltIn": false,
   "actions": {
-    "edit": true,
+    "rename": true,
     "setAsDefault": true,
     "copy": true,
-    "associateProjects": true
+    "associateProjects": true,
+    "delete": true,
+    "manageConditions": true
   }
 }
index f4f78c3f60568972b2b5d753dc757759784f8bdf..edc04d97103dd746197c0eea0bf9997b7425312f 100644 (file)
@@ -141,7 +141,8 @@ public class ListActionTest {
   @Test
   public void actions_with_quality_gate_administer_permission() {
     userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES, defaultOrganizationProvider.get().getUuid());
-    QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Sonar way").setBuiltIn(true));
+    QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Default").setBuiltIn(false));
+    QualityGateDto builtInQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Sonar way").setBuiltIn(true));
     QualityGateDto otherQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Sonar way - Without Coverage").setBuiltIn(false));
     db.qualityGates().setDefaultQualityGate(defaultQualityGate);
 
@@ -152,10 +153,12 @@ public class ListActionTest {
       .containsExactlyInAnyOrder(true);
     assertThat(response.getQualitygatesList())
       .extracting(QualityGate::getName,
-        qg -> qg.getActions().getEdit(), qp -> qp.getActions().getCopy(), qp -> qp.getActions().getSetAsDefault(), qp -> qp.getActions().getAssociateProjects())
+        qg -> qg.getActions().getRename(), qg -> qg.getActions().getDelete(), qg -> qg.getActions().getManageConditions(),
+        qp -> qp.getActions().getCopy(), qp -> qp.getActions().getSetAsDefault(), qp -> qp.getActions().getAssociateProjects())
       .containsExactlyInAnyOrder(
-        tuple(defaultQualityGate.getName(), false, true, false, false),
-        tuple(otherQualityGate.getName(), true, true, true, true));
+        tuple(defaultQualityGate.getName(), true, false, true, true, false, false),
+        tuple(builtInQualityGate.getName(), false, false, false, true, true, true),
+        tuple(otherQualityGate.getName(), true, true, true, true, true, true));
   }
 
   @Test
@@ -172,10 +175,11 @@ public class ListActionTest {
       .containsExactlyInAnyOrder(false);
     assertThat(response.getQualitygatesList())
       .extracting(QualityGate::getName,
-        qg -> qg.getActions().getEdit(), qp -> qp.getActions().getCopy(), qp -> qp.getActions().getSetAsDefault(), qp -> qp.getActions().getAssociateProjects())
+        qg -> qg.getActions().getRename(), qg -> qg.getActions().getDelete(), qg -> qg.getActions().getManageConditions(),
+        qp -> qp.getActions().getCopy(), qp -> qp.getActions().getSetAsDefault(), qp -> qp.getActions().getAssociateProjects())
       .containsExactlyInAnyOrder(
-        tuple(defaultQualityGate.getName(), false, false, false, false),
-        tuple(otherQualityGate.getName(), false, false, false, false));
+        tuple(defaultQualityGate.getName(), false, false, false, false, false, false),
+        tuple(otherQualityGate.getName(), false, false, false, false, false, false));
   }
 
   @Test
index 07da702aeac0b298f22f8c4c85981e51dd546cc1..074b89347629f5a239e9d142f179373f95e00f25 100644 (file)
@@ -156,7 +156,9 @@ public class ShowActionTest {
       .executeProtobuf(ShowWsResponse.class);
 
     Actions actions = response.getActions();
-    assertThat(actions.getEdit()).isTrue();
+    assertThat(actions.getRename()).isTrue();
+    assertThat(actions.getManageConditions()).isTrue();
+    assertThat(actions.getDelete()).isTrue();
     assertThat(actions.getCopy()).isTrue();
     assertThat(actions.getSetAsDefault()).isTrue();
     assertThat(actions.getAssociateProjects()).isTrue();
@@ -172,7 +174,9 @@ public class ShowActionTest {
       .executeProtobuf(ShowWsResponse.class);
 
     Actions actions = response.getActions();
-    assertThat(actions.getEdit()).isTrue();
+    assertThat(actions.getRename()).isTrue();
+    assertThat(actions.getManageConditions()).isTrue();
+    assertThat(actions.getDelete()).isFalse();
     assertThat(actions.getCopy()).isTrue();
     assertThat(actions.getSetAsDefault()).isFalse();
     assertThat(actions.getAssociateProjects()).isFalse();
@@ -187,7 +191,9 @@ public class ShowActionTest {
       .executeProtobuf(ShowWsResponse.class);
 
     Actions actions = response.getActions();
-    assertThat(actions.getEdit()).isFalse();
+    assertThat(actions.getRename()).isFalse();
+    assertThat(actions.getManageConditions()).isFalse();
+    assertThat(actions.getDelete()).isFalse();
     assertThat(actions.getCopy()).isTrue();
     assertThat(actions.getSetAsDefault()).isTrue();
     assertThat(actions.getAssociateProjects()).isTrue();
@@ -202,7 +208,9 @@ public class ShowActionTest {
       .executeProtobuf(ShowWsResponse.class);
 
     Actions actions = response.getActions();
-    assertThat(actions.getEdit()).isFalse();
+    assertThat(actions.getRename()).isFalse();
+    assertThat(actions.getManageConditions()).isFalse();
+    assertThat(actions.getDelete()).isFalse();
     assertThat(actions.getCopy()).isFalse();
     assertThat(actions.getSetAsDefault()).isFalse();
     assertThat(actions.getAssociateProjects()).isFalse();
index e7355755459b6a6ab4c0766026f306252a7a1184..08e1c4570dd4fbc14e582dd047137d0dd4a35229 100644 (file)
@@ -157,10 +157,12 @@ message ListWsResponse {
 }
 
 message Actions {
-  optional bool edit = 1;
+  optional bool rename = 1;
   optional bool setAsDefault = 2;
   optional bool copy = 3;
   optional bool associateProjects = 4;
+  optional bool delete = 5;
+  optional bool manageConditions = 6;
 }