##// END OF EJS Templates
Merged r11513 from trunk (#13328)....
Jean-Philippe Lang -
r11285:b0fa5e7305f8
parent child
Show More
@@ -1146,20 +1146,27 class Issue < ActiveRecord::Base
1146 end
1146 end
1147
1147
1148 unless @copied_from.leaf? || @copy_options[:subtasks] == false
1148 unless @copied_from.leaf? || @copy_options[:subtasks] == false
1149 @copied_from.children.each do |child|
1149 copy_options = (@copy_options || {}).merge(:subtasks => false)
1150 copied_issue_ids = {@copied_from.id => self.id}
1151 @copied_from.reload.descendants.reorder("#{Issue.table_name}.lft").each do |child|
1152 # Do not copy self when copying an issue as a descendant of the copied issue
1153 next if child == self
1154 # Do not copy subtasks of issues that were not copied
1155 next unless copied_issue_ids[child.parent_id]
1156 # Do not copy subtasks that are not visible to avoid potential disclosure of private data
1150 unless child.visible?
1157 unless child.visible?
1151 # Do not copy subtasks that are not visible to avoid potential disclosure of private data
1152 logger.error "Subtask ##{child.id} was not copied during ##{@copied_from.id} copy because it is not visible to the current user" if logger
1158 logger.error "Subtask ##{child.id} was not copied during ##{@copied_from.id} copy because it is not visible to the current user" if logger
1153 next
1159 next
1154 end
1160 end
1155 copy = Issue.new.copy_from(child, @copy_options)
1161 copy = Issue.new.copy_from(child, copy_options)
1156 copy.author = author
1162 copy.author = author
1157 copy.project = project
1163 copy.project = project
1158 copy.parent_issue_id = id
1164 copy.parent_issue_id = copied_issue_ids[child.parent_id]
1159 # Children subtasks are copied recursively
1160 unless copy.save
1165 unless copy.save
1161 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
1166 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
1167 next
1162 end
1168 end
1169 copied_issue_ids[child.id] = copy.id
1163 end
1170 end
1164 end
1171 end
1165 @after_create_from_copy_handled = true
1172 @after_create_from_copy_handled = true
@@ -849,6 +849,49 class IssueTest < ActiveSupport::TestCase
849 assert_equal copy.author, child_copy.author
849 assert_equal copy.author, child_copy.author
850 end
850 end
851
851
852 def test_copy_as_a_child_of_copied_issue_should_not_copy_itself
853 parent = Issue.generate!
854 child1 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 1')
855 child2 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 2')
856
857 copy = parent.reload.copy
858 copy.parent_issue_id = parent.id
859 copy.author = User.find(7)
860 assert_difference 'Issue.count', 3 do
861 assert copy.save
862 end
863 parent.reload
864 copy.reload
865 assert_equal parent, copy.parent
866 assert_equal 3, parent.children.count
867 assert_equal 5, parent.descendants.count
868 assert_equal 2, copy.children.count
869 assert_equal 2, copy.descendants.count
870 end
871
872 def test_copy_as_a_descendant_of_copied_issue_should_not_copy_itself
873 parent = Issue.generate!
874 child1 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 1')
875 child2 = Issue.generate!(:parent_issue_id => parent.id, :subject => 'Child 2')
876
877 copy = parent.reload.copy
878 copy.parent_issue_id = child1.id
879 copy.author = User.find(7)
880 assert_difference 'Issue.count', 3 do
881 assert copy.save
882 end
883 parent.reload
884 child1.reload
885 copy.reload
886 assert_equal child1, copy.parent
887 assert_equal 2, parent.children.count
888 assert_equal 5, parent.descendants.count
889 assert_equal 1, child1.children.count
890 assert_equal 3, child1.descendants.count
891 assert_equal 2, copy.children.count
892 assert_equal 2, copy.descendants.count
893 end
894
852 def test_copy_should_copy_subtasks_to_target_project
895 def test_copy_should_copy_subtasks_to_target_project
853 issue = Issue.generate_with_descendants!
896 issue = Issue.generate_with_descendants!
854
897
General Comments 0
You need to be logged in to leave comments. Login now