aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2012-03-28 19:19:36 +0200
committerFabrice Bellingard <bellingard@gmail.com>2012-03-29 09:56:24 +0200
commit15f521dd35c8c3e85ab896bc0392ff774962be1b (patch)
tree3531588ce408f8bad132324208b75b6e043ed1b8 /sonar-server
parent2f09ce0e5291809a85fb89d90af93e1f35b1d741 (diff)
downloadsonarqube-15f521dd35c8c3e85ab896bc0392ff774962be1b.tar.gz
sonarqube-15f521dd35c8c3e85ab896bc0392ff774962be1b.zip
SONAR-3359 Default description for manual rules created on the fly
=> To encourage people to set a real description and not leave it blank.
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_rules_controller.rb9
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb6
2 files changed, 8 insertions, 7 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_rules_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_rules_controller.rb
index 6868c23bfed..8d1f9079885 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_rules_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_rules_controller.rb
@@ -45,14 +45,13 @@ class ManualRulesController < ApplicationController
# Update rule
rule=Rule.manual_rule(params['id'].to_i)
bad_request('Unknown rule') unless rule
-
+ rule.name=(params[:name])
+ rule.description=params[:description]
+ rule.save!
else
# Create rule
- rule=Rule.find_or_create_manual_rule(params[:name], true)
+ rule=Rule.find_or_create_manual_rule(params[:name], true, {:description => params[:description]})
end
- rule.name=(params[:name])
- rule.description=params[:description]
- rule.save!
rescue Exception => e
flash[:error]= e.message
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
index 51d6df0a5fa..71fbd6a411f 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule.rb
@@ -136,14 +136,16 @@ class Rule < ActiveRecord::Base
Rule.find(:first, :conditions => ['enabled=? and plugin_name=? and id=?', true, MANUAL_REPOSITORY_KEY, id])
end
- def self.find_or_create_manual_rule(rule_id_or_name, create_if_not_found=false)
+ def self.find_or_create_manual_rule(rule_id_or_name, create_if_not_found=false, options={})
if Api::Utils.is_integer?(rule_id_or_name)
rule = Rule.find(:first, :conditions => {:enabled => true, :plugin_name => MANUAL_REPOSITORY_KEY, :id => rule_id_or_name.to_i})
else
key = rule_id_or_name.strip.downcase.sub(/\s+/, '_')
rule = Rule.find(:first, :conditions => {:enabled => true, :plugin_name => MANUAL_REPOSITORY_KEY, :plugin_rule_key => key})
if rule==nil && create_if_not_found
- rule = Rule.create!(:enabled => true, :plugin_name => MANUAL_REPOSITORY_KEY, :plugin_rule_key => key, :name => rule_id_or_name)
+ description = options[:description] || Api::Utils.message('manual_rules.should_provide_real_description')
+ rule = Rule.create!(:enabled => true, :plugin_name => MANUAL_REPOSITORY_KEY, :plugin_rule_key => key,
+ :name => rule_id_or_name, :description => description)
end
end
rule