@@ -1147,20 +1147,27 class Issue < ActiveRecord::Base | |||||
1147 | end |
|
1147 | end | |
1148 |
|
1148 | |||
1149 | unless @copied_from.leaf? || @copy_options[:subtasks] == false |
|
1149 | unless @copied_from.leaf? || @copy_options[:subtasks] == false | |
1150 | @copied_from.children.each do |child| |
|
1150 | copy_options = (@copy_options || {}).merge(:subtasks => false) | |
1151 | unless child.visible? |
|
1151 | copied_issue_ids = {@copied_from.id => self.id} | |
|
1152 | @copied_from.reload.descendants.reorder("#{Issue.table_name}.lft").each do |child| | |||
|
1153 | # Do not copy self when copying an issue as a descendant of the copied issue | |||
|
1154 | next if child == self | |||
|
1155 | # Do not copy subtasks of issues that were not copied | |||
|
1156 | next unless copied_issue_ids[child.parent_id] | |||
1152 |
|
|
1157 | # Do not copy subtasks that are not visible to avoid potential disclosure of private data | |
|
1158 | unless child.visible? | |||
1153 | logger.error "Subtask ##{child.id} was not copied during ##{@copied_from.id} copy because it is not visible to the current user" if logger |
|
1159 | logger.error "Subtask ##{child.id} was not copied during ##{@copied_from.id} copy because it is not visible to the current user" if logger | |
1154 | next |
|
1160 | next | |
1155 | end |
|
1161 | end | |
1156 |
copy = Issue.new.copy_from(child, |
|
1162 | copy = Issue.new.copy_from(child, copy_options) | |
1157 | copy.author = author |
|
1163 | copy.author = author | |
1158 | copy.project = project |
|
1164 | copy.project = project | |
1159 | copy.parent_issue_id = id |
|
1165 | copy.parent_issue_id = copied_issue_ids[child.parent_id] | |
1160 | # Children subtasks are copied recursively |
|
|||
1161 | unless copy.save |
|
1166 | unless copy.save | |
1162 | 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 | 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 | |
|
1168 | next | |||
1163 | end |
|
1169 | end | |
|
1170 | copied_issue_ids[child.id] = copy.id | |||
1164 | end |
|
1171 | end | |
1165 | end |
|
1172 | end | |
1166 | @after_create_from_copy_handled = true |
|
1173 | @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