From: Jean-Baptiste Lievremont Date: Thu, 9 Oct 2014 14:38:22 +0000 (+0200) Subject: SONAR-5593 Better handling of profile overwrite on copy X-Git-Tag: 4.5.1-RC1~36 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f579e78c343c3d05015d07d1917e9d37f557e462;p=sonarqube.git SONAR-5593 Better handling of profile overwrite on copy --- diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb index 6956a1287eb..3b00a8a16b0 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb @@ -140,19 +140,37 @@ class ProfilesController < ApplicationController render :partial => 'profiles/copy_form' end - # POST /profiles/copy/?name= + # POST /profiles/copy/?name=[&overwrite=] def copy verify_post_request verify_ajax_request require_parameters 'id' - source_key=profile_id_to_key(params[:id].to_i) + source_id = params[:id].to_i + source_profile = Internal.quality_profiles.profile(source_id) + + source_key=profile_id_to_key(source_id) target_name = params['name'] - call_backend do - Internal.qprofile_service.copyToName(source_key, target_name) - flash[:notice]= message('quality_profiles.profile_x_not_activated', :params => target_name) - render :text => 'ok', :status => 200 + overwrite = (params['overwrite'] == target_name) + target_profile = nil + + unless overwrite + target_profile = Internal.quality_profiles.profile(target_name, source_profile.language()) + end + + if target_profile.nil? || overwrite + call_backend do + Internal.qprofile_service.copyToName(source_key, target_name) + if overwrite + flash[:notice] = message('quality_profiles.copy_x_overwritten', :params => target_name) + else + flash[:notice] = message('quality_profiles.profile_x_not_activated', :params => target_name) + end + render :text => 'ok', :status => 200 + end + else + render :text => message('quality_profiles.copy_overwrite_x', :params => target_name), :status => 409 end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb index ab8a79f4247..71520b05840 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/profiles/_copy_form.html.erb @@ -6,17 +6,37 @@