]> source.dussan.org Git - redmine.git/commitdiff
Fix that updating an issue from context menu to a none value do not set the field...
authorMarius Balteanu <marius.balteanu@zitec.com>
Thu, 5 Aug 2021 23:41:01 +0000 (23:41 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Thu, 5 Aug 2021 23:41:01 +0000 (23:41 +0000)
Patch by Mizuki ISHIKAWA.

git-svn-id: http://svn.redmine.org/redmine/trunk@21139 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/application_controller.rb
app/controllers/issues_controller.rb
test/functional/issues_controller_test.rb

index f907b115983916c421f0f836ceb45f166f40f15b..f671d87f79f0091fb8eedbca2ea9fd561a512dea 100644 (file)
@@ -413,10 +413,18 @@ class ApplicationController < ActionController::Base
 
   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|
+    end
+
+    replace_none_values_with_blank(attributes)
+  end
+
+  def replace_none_values_with_blank(params)
+    attributes = (params || {}))
+    attributes.each_key {|k| attributes[k] = '' if attributes[k] == 'none'}
+    if (custom = attributes[:custom_field_values])
+      custom.each_key do |k|
         if custom[k].is_a?(Array)
           custom[k] << '' if custom[k].delete('__none__')
         else
index 080520ef5d2c5baa302717623e7007a4403f2a3f..96a8341d0b2ea6da5b1d62155e7f51d75ffc919d 100644 (file)
@@ -561,6 +561,7 @@ class IssuesController < ApplicationController
         return false
       end
     end
+    issue_attributes = replace_none_values_with_blank(issue_attributes)
     @issue.safe_attributes = issue_attributes
     @priorities = IssuePriority.active
     @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
index 36d906fd2e71656702bffefbd180dd855d22bbaa..9e77fed121b1aa272127f4bcd945aaf55a67b3dd 100644 (file)
@@ -6660,6 +6660,33 @@ class IssuesControllerTest < Redmine::ControllerTest
     assert_equal 2, issue.reload.assigned_to_id
   end
 
+  def test_update_with_value_of_none_should_set_the_values_to_blank
+    @request.session[:user_id] = 2
+    issue = Issue.find(1)
+    issue.custom_field_values = {1 => 'MySQL'}
+    issue.assigned_to_id = 2
+    issue.save!
+
+    put(
+      :update,
+      params: {
+        id: issue.id,
+        issue: {
+          assigned_to_id: 'none',
+          category_id: 'none',
+          fixed_version_id: 'none',
+          custom_field_values: { 1 => '__none__' }
+        }
+      }
+    )
+
+    issue.reload
+    assert_nil issue.assigned_to
+    assert_nil issue.category
+    assert_nil issue.fixed_version
+    assert_equal '', issue.custom_field_value(1)
+  end
+
   def test_get_bulk_edit
     @request.session[:user_id] = 2
     get(:bulk_edit, :params => {:ids => [1, 3]})