summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-04-06 11:56:30 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-04-06 11:56:30 +0000
commit07d20cc5f70b55787296539276f198cc47004ae7 (patch)
treedc9bfaf1402d0d3fc5b3f7182db25b6dca2627e9
parentdee17f4677498a8e3e81beac0622762165fa129d (diff)
downloadredmine-07d20cc5f70b55787296539276f198cc47004ae7.tar.gz
redmine-07d20cc5f70b55787296539276f198cc47004ae7.zip
Let non required list/user/version custom fields to be set to blank when bulk editing (#10605).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9349 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/issues_controller.rb11
-rw-r--r--app/helpers/custom_fields_helper.rb1
-rw-r--r--test/functional/issues_controller_test.rb31
3 files changed, 39 insertions, 4 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index f8d982c12..5621fbbe8 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -420,7 +420,16 @@ private
def parse_params_for_bulk_issue_attributes(params)
attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
- attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
+ if custom = attributes[:custom_field_values]
+ custom.reject! {|k,v| v.blank?}
+ custom.keys.each do |k|
+ if custom[k].is_a?(Array)
+ custom[k] << '' if custom[k].delete('__none__')
+ else
+ custom[k] = '' if custom[k] == '__none__'
+ end
+ end
+ end
attributes
end
end
diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb
index 7d1368fa8..5e63a5634 100644
--- a/app/helpers/custom_fields_helper.rb
+++ b/app/helpers/custom_fields_helper.rb
@@ -100,6 +100,7 @@ module CustomFieldsHelper
when "list"
options = []
options << [l(:label_no_change_option), ''] unless custom_field.multiple?
+ options << [l(:label_none), '__none__'] unless custom_field.is_required?
options += custom_field.possible_values_options(projects)
select_tag(field_name, options_for_select(options),
:id => field_id, :multiple => custom_field.multiple?)
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index e91acb20c..217d6e68f 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -2665,7 +2665,7 @@ class IssuesControllerTest < ActionController::TestCase
:attributes => {:name => "issue[custom_field_values][#{field.id}]"},
:children => {
:only => {:tag => 'option'},
- :count => Project.find(1).users.count + 1
+ :count => Project.find(1).users.count + 2 # "no change" + "none" options
}
end
@@ -2681,7 +2681,7 @@ class IssuesControllerTest < ActionController::TestCase
:attributes => {:name => "issue[custom_field_values][#{field.id}]"},
:children => {
:only => {:tag => 'option'},
- :count => Project.find(1).shared_versions.count + 1
+ :count => Project.find(1).shared_versions.count + 2 # "no change" + "none" options
}
end
@@ -2698,7 +2698,7 @@ class IssuesControllerTest < ActionController::TestCase
:attributes => {:name => "issue[custom_field_values][1][]"},
:children => {
:only => {:tag => 'option'},
- :count => 3
+ :count => field.possible_values.size + 1 # "none" options
}
end
@@ -2924,6 +2924,17 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal '777', journal.details.first.value
end
+ def test_bulk_update_custom_field_to_blank
+ @request.session[:user_id] = 2
+ post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
+ :issue => {:priority_id => '',
+ :assigned_to_id => '',
+ :custom_field_values => {'1' => '__none__'}}
+ assert_response 302
+ assert_equal '', Issue.find(1).custom_field_value(1)
+ assert_equal '', Issue.find(3).custom_field_value(1)
+ end
+
def test_bulk_update_multi_custom_field
field = CustomField.find(1)
field.update_attribute :multiple, true
@@ -2942,6 +2953,20 @@ class IssuesControllerTest < ActionController::TestCase
assert_nil Issue.find(2).custom_field_value(1)
end
+ def test_bulk_update_multi_custom_field_to_blank
+ field = CustomField.find(1)
+ field.update_attribute :multiple, true
+
+ @request.session[:user_id] = 2
+ post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
+ :issue => {:priority_id => '',
+ :assigned_to_id => '',
+ :custom_field_values => {'1' => ['__none__']}}
+ assert_response 302
+ assert_equal [''], Issue.find(1).custom_field_value(1)
+ assert_equal [''], Issue.find(3).custom_field_value(1)
+ end
+
def test_bulk_update_unassign
assert_not_nil Issue.find(2).assigned_to
@request.session[:user_id] = 2