Commit 09b9e330 authored by jplang's avatar jplang

Add warning when loosing data from custom fields when bulk editing issues (#22600).

git-svn-id: https://svn.redmine.org/redmine/trunk@16224 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent a7a86bb6
......@@ -213,6 +213,16 @@ class IssuesController < ApplicationController
edited_issues = Issue.where(:id => @issues.map(&:id)).to_a
@values_by_custom_field = {}
edited_issues.each do |issue|
issue.custom_field_values.each do |c|
if c.value_present?
@values_by_custom_field[c.custom_field] ||= []
@values_by_custom_field[c.custom_field] << issue.id
end
end
end
@allowed_projects = Issue.allowed_target_projects
if params[:issue]
@target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
......@@ -244,6 +254,15 @@ class IssuesController < ApplicationController
end
end
edited_issues.each do |issue|
issue.custom_field_values.each do |c|
if c.value_present? && @values_by_custom_field[c.custom_field]
@values_by_custom_field[c.custom_field].delete(issue.id)
end
end
end
@values_by_custom_field.delete_if {|k,v| v.blank?}
@custom_fields = edited_issues.map{|i|i.editable_custom_fields}.reduce(:&).select {|field| field.format.bulk_edit_supported}
@assignables = target_projects.map(&:assignable_users).reduce(:&)
@versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
......
......@@ -52,6 +52,14 @@ class CustomFieldValue
@value = custom_field.set_custom_field_value(self, v)
end
def value_present?
if value.is_a?(Array)
value.any?(&:present?)
else
value.present?
end
end
def validate_value
custom_field.validate_custom_value(self).each do |message|
customized.errors.add(:base, custom_field.name + ' ' + message)
......
......@@ -186,6 +186,13 @@
</fieldset>
</div>
<% if @values_by_custom_field.present? %>
<div class="flash warning">
<%= l(:warning_fields_cleared_on_bulk_edit) %>:<br />
<%= safe_join(@values_by_custom_field.map {|field, ids| content_tag "span", "#{field.name} (#{ids.size})"}, ', ') %>
</div>
<% end %>
<p>
<% if @copy %>
<%= hidden_field_tag 'copy', '1' %>
......
......@@ -219,6 +219,7 @@ en:
error_no_projects_with_tracker_allowed_for_new_issue: "There are no projects with trackers for which you can create an issue"
error_move_of_child_not_possible: "Subtask %{child} could not be moved to the new project: %{errors}"
error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: "Spent time cannot be reassigned to an issue that is about to be deleted"
warning_fields_cleared_on_bulk_edit: "Changes will result in the automatic deletion of values from one or more fields on the selected objects"
mail_subject_lost_password: "Your %{value} password"
mail_body_lost_password: 'To change your password, click on the following link:'
......
......@@ -239,6 +239,7 @@ fr:
error_no_projects_with_tracker_allowed_for_new_issue: "Aucun projet ne dispose d'un tracker sur lequel vous pouvez créer une demande"
error_move_of_child_not_possible: "La sous-tâche %{child} n'a pas pu être déplacée dans le nouveau projet : %{errors}"
error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted: "Le temps passé ne peut pas être réaffecté à une demande qui va être supprimée"
warning_fields_cleared_on_bulk_edit: "Les changements apportés entraîneront la suppression automatique des valeurs d'un ou plusieurs champs sur les objets sélectionnés"
mail_subject_lost_password: "Votre mot de passe %{value}"
mail_body_lost_password: 'Pour changer votre mot de passe, cliquez sur le lien suivant :'
......
......@@ -4067,6 +4067,23 @@ class IssuesControllerTest < Redmine::ControllerTest
assert_select 'input[name=?]', "issue[custom_field_values][#{field2.id}]"
end
def test_bulk_edit_should_warn_about_custom_field_values_about_to_be_cleared
CustomField.delete_all
cleared = IssueCustomField.generate!(:name => 'Cleared', :tracker_ids => [2], :is_for_all => true)
CustomValue.create!(:customized => Issue.find(2), :custom_field => cleared, :value => 'foo')
not_cleared = IssueCustomField.generate!(:name => 'Not cleared', :tracker_ids => [2, 3], :is_for_all => true)
CustomValue.create!(:customized => Issue.find(2), :custom_field => not_cleared, :value => 'bar')
@request.session[:user_id] = 2
get :bulk_edit, :ids => [1, 2], :issue => {:tracker_id => 3}
assert_response :success
assert_select '.warning', :text => /automatic deletion of values/
assert_select '.warning span', :text => 'Cleared (1)'
assert_select '.warning span', :text => /Not cleared/, :count => 0
end
def test_bulk_update
@request.session[:user_id] = 2
# update issues priority
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment