From 8569b5c29e3577cd2137e9680ea79f4e5ee6db7c Mon Sep 17 00:00:00 2001 From: Godin Date: Tue, 21 Dec 2010 11:49:41 +0000 Subject: [PATCH] SONAR-1722: Don't allow to delete inherited profile --- .../sonar/server/configuration/ProfilesManager.java | 3 +-- .../server/configuration/InheritedProfilesTest.java | 7 +++++++ .../shouldNotDeleteInheritedProfile-result.xml | 12 ++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldNotDeleteInheritedProfile-result.xml 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 @@ -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 index 00000000000..fd3b5e3e589 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldNotDeleteInheritedProfile-result.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + -- 2.39.5