diff options
author | Godin <mandrikov@gmail.com> | 2010-12-21 11:49:41 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-21 11:49:41 +0000 |
commit | 8569b5c29e3577cd2137e9680ea79f4e5ee6db7c (patch) | |
tree | d7c0b4fd0229cd307fb781191303898916d7720d /sonar-server | |
parent | e0384295ca97c8d6d9906494925e071d5174cb02 (diff) | |
download | sonarqube-8569b5c29e3577cd2137e9680ea79f4e5ee6db7c.tar.gz sonarqube-8569b5c29e3577cd2137e9680ea79f4e5ee6db7c.zip |
SONAR-1722: Don't allow to delete inherited profile
Diffstat (limited to 'sonar-server')
3 files changed, 20 insertions, 2 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java index 147e8132f70..1c6114ba386 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java @@ -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); diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/InheritedProfilesTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/InheritedProfilesTest.java index beaee7eb60c..d3ea548b69e 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/InheritedProfilesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/InheritedProfilesTest.java @@ -35,6 +35,13 @@ public class InheritedProfilesTest extends AbstractDbUnitTestCase { } @Test + public void shouldNotDeleteInheritedProfile() { + setupData("shouldCheckCycles"); + profilesManager.deleteProfile(1); + checkTables("shouldNotDeleteInheritedProfile", "rules_profiles"); + } + + @Test public void shouldSetParent() { setupData("shouldSetParent"); profilesManager.changeParentProfile(2, "parent"); 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 index 00000000000..fd3b5e3e589 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldNotDeleteInheritedProfile-result.xml @@ -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> |