]> source.dussan.org Git - redmine.git/commitdiff
Merged r15532 to r15534 (#23054).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 18 Jun 2016 06:01:43 +0000 (06:01 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 18 Jun 2016 06:01:43 +0000 (06:01 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@15537 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/application_controller.rb
app/controllers/issues_controller.rb
app/controllers/timelog_controller.rb
test/functional/timelog_controller_test.rb

index 48ad635e8456e1428d2740afd5fe02f7a39080c3..f998be77534005c7c18e5fa5e5c3ce7799ed2b09 100644 (file)
@@ -352,6 +352,22 @@ class ApplicationController < ActionController::Base
     @attachments = att || []
   end
 
+  def parse_params_for_bulk_update(params)
+    attributes = (params || {}).reject {|k,v| v.blank?}
+    attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
+    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
+
   # make sure that the user is a member of the project (or admin) if project is private
   # used as a before_filter for actions that do not require any particular permission on the project
   def check_project_privacy
index 95c58674cee8caab53133f4f8e1ea9415a65baaf..b842023a780debb0b3f1841a3e3d2370aeb9ccb3 100644 (file)
@@ -252,7 +252,7 @@ class IssuesController < ApplicationController
     @issues.sort!
     @copy = params[:copy].present?
 
-    attributes = parse_params_for_bulk_issue_attributes(params)
+    attributes = parse_params_for_bulk_update(params[:issue])
     copy_subtasks = (params[:copy_subtasks] == '1')
     copy_attachments = (params[:copy_attachments] == '1')
 
@@ -495,22 +495,6 @@ class IssuesController < ApplicationController
     @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
   end
 
-  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'}
-    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
-
   # Saves @issue and a time_entry from the parameters
   def save_issue_with_child_records
     Issue.transaction do
index 597160191ee4eebf3c9cc4365268ee84b6c918fe..66ae976784c3ef195388d8c823c87b82f2a5ce07 100644 (file)
@@ -174,7 +174,7 @@ class TimelogController < ApplicationController
   end
 
   def bulk_update
-    attributes = parse_params_for_bulk_time_entry_attributes(params)
+    attributes = parse_params_for_bulk_update(params[:time_entry])
 
     unsaved_time_entry_ids = []
     @time_entries.each do |time_entry|
@@ -271,11 +271,4 @@ private
     end
     scope
   end
-
-  def parse_params_for_bulk_time_entry_attributes(params)
-    attributes = (params[:time_entry] || {}).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]
-    attributes
-  end
 end
index ce6f5936c52fa3e381931a49b902825ae72a255e..c3e96793df030b8a34718170222782390cb1cd13 100644 (file)
@@ -527,6 +527,15 @@ class TimelogControllerTest < ActionController::TestCase
     assert_equal ["0", "0"], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(10).value}
   end
 
+  def test_bulk_update_clear_custom_field
+    field = TimeEntryCustomField.generate!(:field_format => 'string')
+    @request.session[:user_id] = 2
+    post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {field.id.to_s => '__none__'} }
+
+    assert_response 302
+    assert_equal ["", ""], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(field).value}
+  end
+
   def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
     @request.session[:user_id] = 2
     post :bulk_update, :ids => [1,2], :back_url => '/time_entries'