diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-10-09 16:38:22 +0200 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-10-14 14:51:32 +0200 |
commit | f579e78c343c3d05015d07d1917e9d37f557e462 (patch) | |
tree | 5bda4fb0d78d8a3a339b46203daa4cfc813df2cf | |
parent | 5e7744ae006b41948359fe60841e8e66701fc5f9 (diff) | |
download | sonarqube-f579e78c343c3d05015d07d1917e9d37f557e462.tar.gz sonarqube-f579e78c343c3d05015d07d1917e9d37f557e462.zip |
SONAR-5593 Better handling of profile overwrite on copy
3 files changed, 47 insertions, 7 deletions
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/<id>?name=<name of new profile> + # POST /profiles/copy/<id>?name=<name of new profile>[&overwrite=<name of overwritten profile>] 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 @@ </div> <div class="modal-body"> <div class="modal-error"/> + <div class="modal-warning"/> <div class="modal-field"> <label for="name"><%= message 'quality_profiles.copy_new_name' -%> <em class="mandatory">*</em></label> <input id="copy-name" name="name" type="text" size="50" maxlength="100" autofocus="autofocus"/> </div> </div> <div class="modal-foot"> + <input type="hidden" value="" name="overwrite" id="copy-overwrite"/> <input type="submit" value="<%= h message('copy') -%>" id="copy-submit"/> <a href="#" onclick="return closeModalWindow()" id="copy-cancel"><%= h message('cancel') -%></a> </div> </fieldset> </form> <script> - $j("#copy-profile-form").modalForm(); + $j("#copy-profile-form").modalForm({ + error: function (xhr) { + if (xhr.status == 409) { + $j('#copy-profile-form .modal-error').hide(); + var warningElt = $j('#copy-profile-form .modal-warning'); + $j('#copy-overwrite').val($j('#copy-name').val()); + $j('#copy-profile-form input[type=submit]').removeAttr('disabled'); + warningElt.html(xhr.responseText); + warningElt.show(); + } else { + $j('#copy-profile-form .modal-warning').hide(); + var errorElt = $j('#copy-profile-form .modal-error'); + $j('.loading-image').addClass("hidden"); + $j('#copy-profile-form input[type=submit]').removeAttr('disabled'); + errorElt.html(xhr.responseText); + errorElt.show(); + } + } + }); </script> diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 5c7a8ea6563..bd72fe78a44 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1640,6 +1640,8 @@ quality_profiles.remove_projects_confirm_message=Are you sure that you want to d quality_profiles.remove_projects_confirm_button=Remove All quality_profiles.copy_x_title=Copy Profile {0} quality_profiles.copy_new_name=New name +quality_profiles.copy_overwrite_x=You are about to copy this quality profile into the existing "{0}" profile, which will fully overwrite it. Please confirm the name if you want to overwrite, or choose another name. +quality_profiles.copy_x_overwritten=Profile '{0}' has been overwritten. quality_profiles.restore_built_in_profiles=Restore Built-in Profiles quality_profiles.restore_built_in_profiles_confirmation=Are you sure you want to restore '{0}' profile(s) for '{1}' ? quality_profiles.including=including |