Project

General

Profile

Defect #17068 » #17068-copy-subtask-issue-relationships_for5.3.1.patch

Markus Boremski, 2024-08-30 12:57

View differences:

app/models/issue.rb
1750 1750

  
1751 1751
    unless @copied_from.leaf? || @copy_options[:subtasks] == false
1752 1752
      copy_options = (@copy_options || {}).merge(:subtasks => false)
1753
      copied_issue_ids = {@copied_from.id => self.id}
1753
      copied_issues = {@copied_from.id => self}
1754 1754
      @copied_from.reload.descendants.reorder("#{Issue.table_name}.lft").each do |child|
1755 1755
        # Do not copy self when copying an issue as a descendant of the copied issue
1756 1756
        next if child == self
1757 1757
        # Do not copy subtasks of issues that were not copied
1758
        next unless copied_issue_ids[child.parent_id]
1758
        next unless copied_issues[child.parent_id]
1759 1759

  
1760 1760
        # Do not copy subtasks that are not visible to avoid potential disclosure of private data
1761 1761
        unless child.visible?
1762 1762
          if logger
app/models/issue.rb
1773 1773
        end
1774 1774
        copy.author = author
1775 1775
        copy.project = project
1776
        copy.parent_issue_id = copied_issue_ids[child.parent_id]
1776
        copy.parent_issue_id = copied_issues[child.parent_id].id
1777 1777
        unless child.fixed_version.present? && child.fixed_version.status == 'open'
1778 1778
          copy.fixed_version_id = nil
1779 1779
        end
1780 1780
        unless child.assigned_to_id.present? &&
1781 1781
                 child.assigned_to.status == User::STATUS_ACTIVE
1782 1782
          copy.assigned_to = nil
1783 1783
        end
1784 1784
        unless copy.save
1785 1785
          if logger
1786 1786
            logger.error(
1787 1787
              "Could not copy subtask ##{child.id} " \
1788 1788
                "while copying ##{@copied_from.id} to ##{id} due to validation errors: " \
1789 1789
                "#{copy.errors.full_messages.join(', ')}"
1790 1790
            )
1791 1791
          end
1792 1792
          next
1793 1793
        end
1794
        copied_issue_ids[child.id] = copy.id
1794
        copied_issues[child.id] = copy
1795
      end
1796

  
1797
      # Replicate dependencies between copied children
1798
      @copied_from.reload.descendants.reorder("#{Issue.table_name}.lft").each do |child|
1799
        copy = copied_issues[child.id]
1800
        next unless copy
1801
        child.relations_to.each do |rel|
1802
          next unless copied_issues.key?(rel.issue_from.id)
1803
          from = Issue.find_by_id(copied_issues[rel.issue_from.id].id)
1804
          next unless from
1805
          relation = IssueRelation.new(:issue_from => from, :issue_to => copy, :relation_type => rel.relation_type)
1806
          unless relation.save
1807
            logger.error "Could not create relation while copying ##{child.id} to ##{copy.id} due to validation errors: #{relation.errors.full_messages.join(', ')}" if logger
1808
          end
1809
        end
1795 1810
      end
1796 1811
    end
1797 1812
    @after_create_from_copy_handled = true
(2-2/2)