]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1722: Don't allow to delete inherited profile
authorGodin <mandrikov@gmail.com>
Tue, 21 Dec 2010 11:49:41 +0000 (11:49 +0000)
committerGodin <mandrikov@gmail.com>
Tue, 21 Dec 2010 11:49:41 +0000 (11:49 +0000)
sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
sonar-server/src/test/java/org/sonar/server/configuration/InheritedProfilesTest.java
sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldNotDeleteInheritedProfile-result.xml [new file with mode: 0644]

index 147e8132f70944fde77546407f2ccdd0350f73bd..1c6114ba386af753c5fdb7d30efe729ae9735868 100644 (file)
@@ -50,9 +50,8 @@ public class ProfilesManager extends BaseDao {
   }
 
   public void deleteProfile(int profileId) {
-    // TODO should support deletion of profile with children
     RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId);
-    if (profile != null && !profile.getProvided()) {
+    if (profile != null && !profile.getProvided() && getChildren(profile).isEmpty()) {
       String hql = "UPDATE " + ResourceModel.class.getSimpleName() + " o SET o.rulesProfile=null WHERE o.rulesProfile=:rulesProfile";
       getSession().createQuery(hql).setParameter("rulesProfile", profile).executeUpdate();
       getSession().remove(profile);
index beaee7eb60cb060ccbf2ecba29a5d67a52b7d292..d3ea548b69e6d4ea84086c547928d186dcc26198 100644 (file)
@@ -34,6 +34,13 @@ public class InheritedProfilesTest extends AbstractDbUnitTestCase {
     assertThat(profilesManager.isCycle(level2, level3), is(true));
   }
 
+  @Test
+  public void shouldNotDeleteInheritedProfile() {
+    setupData("shouldCheckCycles");
+    profilesManager.deleteProfile(1);
+    checkTables("shouldNotDeleteInheritedProfile", "rules_profiles");
+  }
+
   @Test
   public void shouldSetParent() {
     setupData("shouldSetParent");
diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldNotDeleteInheritedProfile-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldNotDeleteInheritedProfile-result.xml
new file mode 100644 (file)
index 0000000..fd3b5e3
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+
+  <rules id="1" name="foo" description="test" plugin_config_key="checker/foo"
+         plugin_rule_key="checkstyle.rule1" plugin_name="plugin" enabled="true" cardinality="SINGLE" parent_id="[null]"/>
+
+  <rules_profiles id="1" provided="false" name="level1" default_profile="0" language="java" parent_name="[null]"/>
+  
+  <rules_profiles id="2" provided="false" name="level2" default_profile="0" language="java" parent_name="level1"/>
+  
+  <rules_profiles id="3" provided="false" name="level3" default_profile="0" language="java" parent_name="level2"/>
+
+</dataset>