From b72d40a4292ab43b1a09b8b214b90574c5aba140 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 8 Sep 2012 06:14:35 +0000 Subject: [PATCH] Do not copy subtasks twice when copying an issue and its descendants (#6965). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10329 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 7 +++++++ test/functional/issues_controller_test.rb | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index c2ab10e61..9f34a0185 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -235,6 +235,13 @@ class IssuesController < ApplicationController unsaved_issue_ids = [] moved_issues = [] + + if @copy && params[:copy_subtasks].present? + # Descendant issues will be copied with the parent task + # Don't copy them twice + @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}} + end + @issues.each do |issue| issue.reload if @copy diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 9488b5331..fdd995c56 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -3539,6 +3539,21 @@ class IssuesControllerTest < ActionController::TestCase assert_equal count, copy.descendants.count end + def test_bulk_copy_should_not_copy_selected_subtasks_twice + issue = Issue.generate_with_descendants!(Project.find(1), :subject => 'Parent') + count = issue.descendants.count + @request.session[:user_id] = 2 + + assert_difference 'Issue.count', count+1 do + post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1', + :issue => { + :project_id => '' + } + end + copy = Issue.where(:parent_id => nil).order("id DESC").first + assert_equal count, copy.descendants.count + end + def test_bulk_copy_to_another_project_should_follow_when_needed @request.session[:user_id] = 2 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'