aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-17 18:50:33 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-17 18:51:04 +0200
commitc83b1e7896b2e1d05f2c80b0c9b2d627b67c9ac5 (patch)
treef234d148add056aa99fe0f6ea336cb7c86e9d227 /server/sonar-web/src/main
parent123eaf25e79b8f15dbc90dd1678e861d49b3d41e (diff)
downloadsonarqube-c83b1e7896b2e1d05f2c80b0c9b2d627b67c9ac5.tar.gz
sonarqube-c83b1e7896b2e1d05f2c80b0c9b2d627b67c9ac5.zip
SONAR-4693 Update error message while creating manual metric with same key as standard metric
Diffstat (limited to 'server/sonar-web/src/main')
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb
index 591eddc9993..a2139496667 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb
@@ -63,13 +63,22 @@ class MetricsController < ApplicationController
def save_from_web
short_name = params[:metric][:short_name]
metric_name = short_name.downcase.gsub(/\s/, '_')[0..59]
-
+
+ @errors = []
if params[:id]
metric = Metric.find(params[:id].to_i)
else
metric = Metric.first(:conditions => ["name = ?", metric_name])
if metric
- @reactivate_metric = metric
+ if metric.origin != Metric::ORIGIN_GUI
+ @errors << "A standard metric named '#{metric_name}' already exists. Please change the name of the manual metric you want to create."
+ @metric = Metric.new
+ @domains = metric.domain
+ render :partial => 'metrics/create_form', :status => 400
+ return
+ else
+ @reactivate_metric = metric
+ end
else
metric = Metric.new
end
@@ -99,14 +108,13 @@ class MetricsController < ApplicationController
end
end
rescue
- @errors = []
@errors << metric.errors.full_messages.join("<br/>\n")
end
if @reactivate_metric
prepare_metrics_and_domains
render :partial => 'metrics/reactivate_form', :status => 400
- elsif @errors
+ elsif !@errors.empty?
@metric = metric
@domains = metric.domain
render :partial => 'metrics/create_form', :status => 400