From f1348316027fcc64d4f67b7d2e216e52752f13a1 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Mon, 29 Mar 2021 03:32:38 +0000 Subject: [PATCH] Do not journalize attachments that are added during a "Copy Issue" operation (#34921). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Patch by Jens Krämer. git-svn-id: http://svn.redmine.org/redmine/trunk@20872 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 2 +- test/unit/issue_test.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 50a52f4fa..e5bb30e25 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1887,7 +1887,7 @@ class Issue < ActiveRecord::Base # Callback on file attachment def attachment_added(attachment) - if current_journal && !attachment.new_record? + if current_journal && !attachment.new_record? && !copy? current_journal.journalize_attachment(attachment, :added) end end diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index ae59024e9..34e0162cf 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -1511,6 +1511,23 @@ class IssueTest < ActiveSupport::TestCase assert_equal [3, nil], copy.children.map(&:assigned_to_id) end + def test_copy_should_not_add_attachments_to_journal + set_tmp_attachments_directory + issue = Issue.generate! + copy = Issue.new + copy.init_journal User.find(1) + copy.copy_from issue + + copy.project = issue.project + copy.save_attachments( + { 'p0' => {'file' => mock_file_with_options(:original_filename => 'upload')} } + ) + assert copy.save + assert j = copy.journals.last + assert_equal 1, j.details.size + assert_equal 'relation', j.details[0].property + 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) -- 2.39.5