From 1b9e5dbd00d8c13328a3add55e734f6fc9044c2c Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Wed, 22 Dec 2010 23:25:28 +0000 Subject: [PATCH] do not display the delete button on profiles inherited by other profiles --- .../org/sonar/server/startup/DeleteDeprecatedMeasures.java | 3 +-- .../webapp/WEB-INF/app/controllers/profiles_controller.rb | 2 +- sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb | 4 ++++ .../src/main/webapp/WEB-INF/app/views/profiles/index.html.erb | 2 +- .../webapp/WEB-INF/app/views/profiles/inheritance.html.erb | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sonar-server/src/main/java/org/sonar/server/startup/DeleteDeprecatedMeasures.java b/sonar-server/src/main/java/org/sonar/server/startup/DeleteDeprecatedMeasures.java index 42f23331663..eed02cc31b4 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/DeleteDeprecatedMeasures.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/DeleteDeprecatedMeasures.java @@ -19,7 +19,6 @@ */ package org.sonar.server.startup; -import org.slf4j.LoggerFactory; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.MeasureModel; import org.sonar.api.platform.ServerUpgradeStatus; @@ -52,7 +51,7 @@ public final class DeleteDeprecatedMeasures { } boolean mustDoPurge() { - return status.isUpgraded() && status.getInitialDbVersion()<=162; + return status.isUpgraded() && status.getInitialDbVersion() <= 162; } void doPurge() { diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb index fcd05e004fd..9ab8bb3d366 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb @@ -93,7 +93,7 @@ class ProfilesController < ApplicationController # def delete @profile = Profile.find(params[:id]) - if @profile && !@profile.provided? && !@profile.default_profile? + if @profile && @profile.deletable? java_facade.deleteProfile(@profile.id) flash[:notice]="Profile '#{@profile.name}' is deleted." end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb index 956e93a7f3d..1c32e082704 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb @@ -100,6 +100,10 @@ class Profile < ActiveRecord::Base @active_hash_by_rule_id end + def deletable? + !provided? && !default_profile? && children.empty? + end + def inherited? parent_name.present? end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb index d402cf272b5..0c75209fe57 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/index.html.erb @@ -137,7 +137,7 @@ - <% if (!(profile.provided?) && !(profile.default_profile?)) %> + <% if profile.deletable? %> <%= button_to "Delete", { :action => 'delete', :id => profile.id }, :class => 'action', :id => "delete_#{u profile.key}", :confirm => "Are you sure that you want to delete the profile '#{profile.name}' ?", diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb index 7d3e1c04da9..50c95d98ec0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/inheritance.html.erb @@ -29,7 +29,7 @@
<% if @profile.provided? %> -

This profile can not be changed.

+

This profile can not be edited.

<% else %>

Set parent:

-- 2.39.5