From: Jean-Baptiste Lievremont Date: Thu, 13 Mar 2014 15:16:13 +0000 (+0100) Subject: SONAR-4366 Remove alert related code from Rails app X-Git-Tag: 4.3~455 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3536e0ab723d4420b437f1d550ffe34119170468;p=sonarqube.git SONAR-4366 Remove alert related code from Rails app --- diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb index 296e92c9b1e..bb9cab54ed9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb @@ -84,7 +84,6 @@ class Api::ProfilesController < Api::ApiController profile = Internal.quality_profiles.profile(params[:name], params[:language]) if profile Internal.quality_profiles.deleteProfile(profile.id()) - Alert.delete_all(['profile_id=?', profile.id()]) end render_success(profile ? 'Profile destroyed' : 'Profile did not exist') @@ -213,14 +212,6 @@ class Api::ProfilesController < Api::ApiController end result[:rules]=rules unless rules.empty? - alerts=[] - @profile.valid_alerts.each do |alert| - alert_hash={:metric => alert.metric.key, :operator => alert.operator} - alert_hash[:error]=alert.value_error if alert.value_error.present? - alert_hash[:warning]=alert.value_warning if alert.value_warning.present? - alerts< 'profiles', :action => 'index') diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/alerts_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/alerts_helper.rb deleted file mode 100644 index 4953a4cf25a..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/alerts_helper.rb +++ /dev/null @@ -1,130 +0,0 @@ -# -# SonarQube, open source software quality management tool. -# Copyright (C) 2008-2014 SonarSource -# mailto:contact AT sonarsource DOT com -# -# SonarQube 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. -# -# SonarQube 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 this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -module AlertsHelper - NUMERIC_THRESOLD_OPERATORS = ['<', '>', '=', '!='] - BOOLEAN_THRESOLD_OPERATORS = ['='] - STRING_THRESOLD_OPERATORS = ['=', '!=', '>', '<'] - LEVEL_THRESOLD_OPERATORS = ['=', '!='] - - def operators_for_alert - NUMERIC_THRESOLD_OPERATORS - end - - def operators_for_select(alert) - if alert.metric.nil? - {} - elsif alert.metric.numeric? - NUMERIC_THRESOLD_OPERATORS - - elsif alert.metric.val_type==Metric::VALUE_TYPE_BOOLEAN - BOOLEAN_THRESOLD_OPERATORS - - elsif alert.metric.val_type==Metric::VALUE_TYPE_STRING - STRING_THRESOLD_OPERATORS - - elsif alert.metric.val_type==Metric::VALUE_TYPE_LEVEL - LEVEL_THRESOLD_OPERATORS - else - {} - end - end - - def default_operator(alert) - if alert.metric.nil? - nil - - elsif alert.metric.numeric? - if alert.metric.qualitative? - alert.metric.direction>0 ? '<' : '>' - else - '>' - end - - elsif alert.metric.val_type==Metric::VALUE_TYPE_BOOLEAN - '=' - - elsif alert.metric.val_type==Metric::VALUE_TYPE_STRING - '=' - - elsif alert.metric.val_type==Metric::VALUE_TYPE_LEVEL - '=' - - else - nil - end - end - - - def value_field(alert, value, fieldname) - if alert.metric.nil? - text_field_tag fieldname, value, :size => 5 - - elsif alert.metric.numeric? - text_field_tag fieldname, value, :size => 5 - - elsif alert.metric.val_type==Metric::VALUE_TYPE_BOOLEAN - select_tag fieldname, options_for_select([['', ''], ['Yes', '1'], ['No', '0']], value) - - elsif alert.metric.val_type==Metric::VALUE_TYPE_STRING - text_field_tag fieldname, value, :size => 5 - - elsif alert.metric.val_type==Metric::VALUE_TYPE_LEVEL - select_tag fieldname, options_for_select([['', ''], ['OK', Metric::TYPE_LEVEL_OK], ['Error', Metric::TYPE_LEVEL_ERROR], ['Warning', Metric::TYPE_LEVEL_WARN]], value) - else - hidden_field_tag fieldname, value - end - end - - def period_select_options(alert) - if alert.metric - select = '' - select << period_select_option(alert, nil) if !alert.metric.name.start_with?("new_") - for index in 1..3 do - select << period_select_option(alert, index) - end - select - end - end - - def period_select_option(alert, index) - if index - selected = (alert.period == index ? 'selected' : '') - "" - else - selected = (alert.period.nil? || alert.period == 0 ? 'selected' : '') - "" - end - end - - def period_label(alert) - index = alert.period - if index - "#{period_label_index(index)}" - else - "#{message('value')}" - end - end - - def period_label_index(index) - "Δ "+ Api::Utils.period_label(index) - end - - -end \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb index f6a69cc81c9..eec11a65007 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/profiles_helper.rb @@ -51,10 +51,6 @@ module ProfilesHelper "#{qProfile.language().to_s}_#{qProfile.name().to_s}" end - def alerts_count(qProfile) - Alert.count(:all, :conditions => ['profile_id=?', qProfile.id()]) - end - def projects_count(qProfile) Internal.quality_profiles.countProjects(qProfile).to_i end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/alert.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/alert.rb deleted file mode 100644 index ade6a6ba2fa..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/alert.rb +++ /dev/null @@ -1,51 +0,0 @@ -# -# SonarQube, open source software quality management tool. -# Copyright (C) 2008-2014 SonarSource -# mailto:contact AT sonarsource DOT com -# -# SonarQube 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. -# -# SonarQube 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 this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -class Alert < ActiveRecord::Base - belongs_to :profile - - validates_presence_of :operator - validates_uniqueness_of :metric_id, :scope => :profile_id - - - def metric=(m) - metric_id=m.id - end - - def metric - Metric.by_id(metric_id) - end - - def name - metric ? metric.short_name : '' - end - - def <=>(other) - name<=>other.name - end - - protected - - def validate - errors.add('Can not set alerts on data metrics.') if metric && metric.val_type==Metric::VALUE_TYPE_DATA - errors.add_to_base('Can not set alerts on alerts.') if metric==Metric.by_key(Metric::ALERT_STATUS) - errors.add_to_base('At least one threshold (warning or error) is required.') if value_error.blank? && value_warning.blank? - end - -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 7e647dae04e..5cf3a2cf369 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 @@ -20,7 +20,6 @@ class Profile < ActiveRecord::Base set_table_name 'rules_profiles' - has_many :alerts, :dependent => :delete_all has_many :active_rules, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :dependent => :destroy, :include => ['rule'] has_many :active_rules_with_params, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :include => ['active_rule_parameters'] has_many :changes, :class_name => 'ActiveRuleChange', :dependent => :destroy @@ -184,10 +183,6 @@ class Profile < ActiveRecord::Base @projects = nil end - def valid_alerts - alerts.reject {|alert| alert.metric.nil? || !alert.metric.enabled } - end - def to_hash_json { :name => name,