#
#
def index
- @profiles = Profile.find(:all, :order => 'name')
+ @profiles = Profile.find(:all, :conditions => ['enabled=?', true], :order => 'name')
end
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}"
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
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?
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
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]
@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
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
+++ /dev/null
- #
- # 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
\r
def self.up\r
add_column(:rules_profiles, :provided, :boolean, :default => false, :null => false)\r
- RulesProfile.reset_column_information\r
+ Profile.reset_column_information\r
end\r
\r
end\r
def self.up
add_column 'rules_profiles', 'language', :string, :limit => 16, :null => true
- RulesProfile.reset_column_information
+ Profile.reset_column_information
end
end
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