From 42179b3f75feacda8e28c53bd963b8a861238537 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 13 Dec 2012 11:57:43 +0100 Subject: [PATCH] SONAR-3825 better error handling during copy of measure filter --- .../app/controllers/measures_controller.rb | 25 +++++++++++-------- .../app/views/measures/_copy_form.html.erb | 14 +++++++---- .../app/views/measures/search.html.erb | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb index a63af45542a..391c759f859 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb @@ -138,18 +138,21 @@ class MeasuresController < ApplicationController access_denied unless logged_in? require_parameters :id - to_clone = find_filter(params[:id]) - @filter = MeasureFilter.new - @filter.name = params[:name] - @filter.description = params[:description] - @filter.user_id = current_user.id - @filter.shared = to_clone.shared - @filter.data = to_clone.data - @filter.shared = false - if @filter.save - current_user.favourited_measure_filters << @filter - render :text => @filter.id.to_s, :status => 200 + source = find_filter(params[:id]) + target = MeasureFilter.new + target.name = params[:name] + target.description = params[:description] + target.user_id = current_user.id + target.shared = source.shared + target.data = source.data + target.shared = false + if target.save + current_user.favourited_measure_filters << target + render :text => target.id.to_s, :status => 200 else + # keep the id (from source) and errors (from target) in the copy form + target.id= source.id + @filter = target render :partial => 'measures/copy_form', :status => 400 end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb index 68eef6d414c..89d14fa379c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/_copy_form.html.erb @@ -2,15 +2,19 @@
-

Copy Filter: <%= h @filter.name -%>

+

Copy Filter

<% @filter.errors.each do |attr, msg| %>

<%= h msg -%>

<% end %> +
+ + +
- +
@@ -24,8 +28,8 @@
\ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb index 242bb0e6f4e..045cb0ac4d1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb @@ -35,7 +35,7 @@ <% end %> <% end %> -
+
<% if @filter.name.present? %> <%= h @filter.name -%> -- 2.39.5