]> source.dussan.org Git - redmine.git/commitdiff
Clear target version when copying an issue if status is locked or closed (#27863).
authorGo MAEDA <maeda@farend.jp>
Thu, 7 Jun 2018 00:33:29 +0000 (00:33 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 7 Jun 2018 00:33:29 +0000 (00:33 +0000)
Patch by Marius BALTEANU.

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

app/models/issue.rb
test/unit/issue_test.rb

index 9b55c2a74072aa11e8d7f3e631860fb8a946a942..0cabeb88f4c5328df6027216b7986de88853f76d 100644 (file)
@@ -1638,6 +1638,7 @@ class Issue < ActiveRecord::Base
         copy.author = author
         copy.project = project
         copy.parent_issue_id = copied_issue_ids[child.parent_id]
+        copy.fixed_version_id = nil unless child.fixed_version.present? && child.fixed_version.status == 'open'
         unless copy.save
           logger.error "Could not copy subtask ##{child.id} while copying ##{@copied_from.id} to ##{id} due to validation errors: #{copy.errors.full_messages.join(', ')}" if logger
           next
index 48a12c6e425470eab5ec8b4302c0a656b8fd2080..0d9f4c25031857c05084a9e1c85aeb301f1cd835 100644 (file)
@@ -1393,6 +1393,26 @@ class IssueTest < ActiveSupport::TestCase
     assert !issue.watched_by?(user2)
   end
 
+  def test_copy_should_clear_subtasks_target_version_if_locked_or_closed
+    version = Version.new(:project => Project.find(1), :name => '2.1',)
+    version.save!
+
+    parent = Issue.generate!
+    child1 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 1', :fixed_version_id => 3)
+    child2 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 2', :fixed_version_id => version.id)
+
+    version.status = 'locked'
+    version.save!
+
+    copy = parent.reload.copy
+
+    assert_difference 'Issue.count', 3 do
+      assert copy.save
+    end
+
+    assert_equal [3, nil], copy.children.map(&:fixed_version_id)
+  end
+
   def test_should_not_call_after_project_change_on_creation
     issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1,
                       :subject => 'Test', :author_id => 1)