From 303de3527f9d9bc4394bf997dfa287a8f7b3b375 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Wed, 2 Feb 2011 12:14:18 +0100 Subject: [PATCH] SONAR-2094 Remove the deprecated ruby model RulesProfile (replaced by Profile) + support the ENABLED column --- .../app/controllers/profiles_controller.rb | 8 +- .../main/webapp/WEB-INF/app/models/profile.rb | 14 +-- .../WEB-INF/app/models/rules_profile.rb | 88 ------------------- .../016_add_rules_profiles_provided_column.rb | 2 +- .../039_add_rules_profiles_language.rb | 2 +- .../055_create_profiles_per_project.rb | 2 +- 6 files changed, 14 insertions(+), 102 deletions(-) delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/models/rules_profile.rb 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 9ab8bb3d366..30ea3658d13 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 @@ -32,7 +32,7 @@ class ProfilesController < ApplicationController # # def index - @profiles = Profile.find(:all, :order => 'name') + @profiles = Profile.find(:all, :conditions => ['enabled=?', true], :order => 'name') end @@ -58,7 +58,7 @@ class ProfilesController < ApplicationController if profile_name.blank?|| language.blank? flash[:warning]='Please type a profile name.' else - profile=Profile.find(:first, :conditions => {:name => profile_name, :language => language}) + profile=Profile.find_by_name_and_language(profile_name, language) if profile flash[:error]="This profile already exists: #{profile_name}" @@ -193,7 +193,7 @@ class ProfilesController < ApplicationController def inheritance @profile = Profile.find(params[:id]) - profiles=Profile.find(:all, :conditions => ['language=? and id<>? and (parent_name is null or parent_name<>?)', @profile.language, @profile.id, @profile.name], :order => 'name') + profiles=Profile.find(:all, :conditions => ['language=? and id<>? and (parent_name is null or parent_name<>?) and enabled=?', @profile.language, @profile.id, @profile.name, true], :order => 'name') @select_parent = [['None', nil]] + profiles.collect{ |profile| [profile.name, profile.name] } end @@ -271,7 +271,7 @@ class ProfilesController < ApplicationController if name.blank? flash[:warning]='Profile name can not be blank.' else - existing=Profile.find(:first, :conditions => {:name => name, :language => profile.language}) + existing=Profile.find(:first, :conditions => {:name => name, :language => profile.language, :enabled => true}) if existing flash[:warning]='This profile name already exists.' elsif !profile.provided? 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 e992d1558de..493a56da9e0 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 @@ -50,20 +50,20 @@ class Profile < ActiveRecord::Base end def self.find_by_name_and_language(name, language) - Profile.find(:first, :conditions => {:name => name, :language => language}) + Profile.find(:first, :conditions => {:name => name, :language => language, :enabled => true}) end def self.find_active_profile_by_language(language) - Profile.find(:first, :conditions => {:default_profile => true, :language => language}) + Profile.find(:first, :conditions => {:default_profile => true, :language => language, :enabled => true}) end def self.default_profile - Profile.find(:first, :conditions => {:default_profile => true}) + Profile.find(:first, :conditions => {:default_profile => true, :enabled => true}) end def set_as_default default_profile=nil - Profile.find(:all, :conditions => {:language => language}).each do |profile| + Profile.find(:all, :conditions => {:language => language, :enabled => true}).each do |profile| if profile.id==id profile.default_profile=true default_profile=profile @@ -81,7 +81,7 @@ class Profile < ActiveRecord::Base def self.options_for_select array=[] - Profile.find(:all, :order => 'name').each do |profile| + Profile.find(:all, :conditions => {:enabled => true}, :order => 'name').each do |profile| label = profile.name label = label + ' (active)' if profile.default_profile? array<<[label, profile.id] @@ -119,7 +119,7 @@ class Profile < ActiveRecord::Base @parent||= begin if parent_name.present? - Profile.find(:first, :conditions => ['language=? and name=?', language, parent_name]) + Profile.find(:first, :conditions => ['language=? and name=? and enabled=?', language, parent_name, true]) else nil end @@ -141,7 +141,7 @@ class Profile < ActiveRecord::Base def children @children ||= begin - Profile.find(:all, :conditions => ['language=? and parent_name=?', language, name], :order => 'name') + Profile.find(:all, :conditions => ['language=? and parent_name=? and enabled=?', language, name, true], :order => 'name') end end end \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rules_profile.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rules_profile.rb deleted file mode 100644 index 9dd57c058fc..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rules_profile.rb +++ /dev/null @@ -1,88 +0,0 @@ - # - # Sonar, entreprise quality control tool. - # Copyright (C) 2009 SonarSource SA - # mailto:contact AT sonarsource DOT com - # - # Sonar is free software; you can redistribute it and/or - # modify it under the terms of the GNU Lesser General Public - # License as published by the Free Software Foundation; either - # version 3 of the License, or (at your option) any later version. - # - # Sonar is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - # Lesser General Public License for more details. - # - # You should have received a copy of the GNU Lesser General Public - # License along with Sonar; if not, write to the Free Software - # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - # - - -# DEPRECATED - use profile.rb instead -class RulesProfile < ActiveRecord::Base - has_many :active_rules, :class_name => 'ActiveRule', :foreign_key => 'profile_id', - :dependent => :destroy, :include => ['rule'] - - has_many :alerts, :class_name => 'Alert', :foreign_key => 'profile_id', - :dependent => :destroy - - has_many :active_rules_with_params, :class_name => 'ActiveRule', :foreign_key => 'profile_id', - :include => ['active_rule_parameters'] - - validates_uniqueness_of :name, :scope => :language, :case_sensitive => false - validates_length_of :name, :in => 1..100, :allow_blank => false - validates_exclusion_of :name, :in => %w( active ), :message => "reserved" - - DEFAULT_PROFILE_NAME = 'Sun checks' - - def self.find_by_name_and_language(name, language) - RulesProfile.find(:first, :conditions => {:name => name, :language => language}) - end - - def self.find_active_profile_by_language(language) - RulesProfile.find(:first, :conditions => {:default_profile => true, :language => language}) - end - - def self.default_profile - RulesProfile.find(:first, :conditions => {:default_profile => true, :language => 'java'}) - end - - def active? - active - end - - def provided? - provided - end - - def active_by_rule_id(rule_id) - active_hash_by_rule_id[rule_id] - end - - def self.options_for_select - array=[] - RulesProfile.find(:all, :order => 'name').each do |profile| - label = profile.name - label = label + ' (active)' if profile.default_profile? - array<<[label, profile.id] - end - array - end - - def unique_key - name + "_" + language - end - - - @active_hash_by_rule_id=nil - def active_hash_by_rule_id - if @active_hash_by_rule_id.nil? - @active_hash_by_rule_id={} - active_rules_with_params.each do |active_rule| - @active_hash_by_rule_id[active_rule.rule_id]=active_rule - end - end - @active_hash_by_rule_id - end -end \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/016_add_rules_profiles_provided_column.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/016_add_rules_profiles_provided_column.rb index d33c87d5f58..0e42e4f4a57 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/016_add_rules_profiles_provided_column.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/016_add_rules_profiles_provided_column.rb @@ -21,7 +21,7 @@ class AddRulesProfilesProvidedColumn < ActiveRecord::Migration def self.up add_column(:rules_profiles, :provided, :boolean, :default => false, :null => false) - RulesProfile.reset_column_information + Profile.reset_column_information end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/039_add_rules_profiles_language.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/039_add_rules_profiles_language.rb index 66ba20b9c17..b242f04d0df 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/039_add_rules_profiles_language.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/039_add_rules_profiles_language.rb @@ -21,6 +21,6 @@ class AddRulesProfilesLanguage < ActiveRecord::Migration def self.up add_column 'rules_profiles', 'language', :string, :limit => 16, :null => true - RulesProfile.reset_column_information + Profile.reset_column_information end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/055_create_profiles_per_project.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/055_create_profiles_per_project.rb index 56dc8e207f8..15b179316a0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/055_create_profiles_per_project.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/055_create_profiles_per_project.rb @@ -23,7 +23,7 @@ class CreateProfilesPerProject < ActiveRecord::Migration add_column :projects, :profile_id, :integer, :null => true Project.reset_column_information rename_column :rules_profiles, :active, :default_profile - RulesProfile.reset_column_information + Profile.reset_column_information end end \ No newline at end of file -- 2.39.5