Defect #17068 » 0001-models-issue-copy-subtask-issue-relationships.patch
| app/models/issue.rb | ||
|---|---|---|
|
unless @copied_from.leaf? || @copy_options[:subtasks] == false
|
||
|
copy_options = (@copy_options || {}).merge(:subtasks => false)
|
||
|
copied_issue_ids = {@copied_from.id => self.id}
|
||
|
copied_issues = {@copied_from.id => self}
|
||
|
@copied_from.reload.descendants.reorder("#{Issue.table_name}.lft").each do |child|
|
||
|
# Do not copy self when copying an issue as a descendant of the copied issue
|
||
|
next if child == self
|
||
|
# Do not copy subtasks of issues that were not copied
|
||
|
next unless copied_issue_ids[child.parent_id]
|
||
|
next unless copied_issues[child.parent_id]
|
||
|
# Do not copy subtasks that are not visible to avoid potential disclosure of private data
|
||
|
unless child.visible?
|
||
|
logger.error "Subtask ##{child.id} was not copied during ##{@copied_from.id} copy because it is not visible to the current user" if logger
|
||
| ... | ... | |
|
end
|
||
|
copy.author = author
|
||
|
copy.project = project
|
||
|
copy.parent_issue_id = copied_issue_ids[child.parent_id]
|
||
|
copy.parent_issue_id = copied_issues[child.parent_id].id
|
||
|
unless copy.save
|
||
|
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
|
||
|
next
|
||
|
end
|
||
|
copied_issue_ids[child.id] = copy.id
|
||
|
copied_issues[child.id] = copy
|
||
|
end
|
||
|
# Replicate dependencies between copied children
|
||
|
@copied_from.reload.descendants.reorder("#{Issue.table_name}.lft").each do |child|
|
||
|
copy = copied_issues[child.id]
|
||
|
next unless copy
|
||
|
child.relations_to.each do |rel|
|
||
|
next unless copied_issues.key?(rel.issue_from.id)
|
||
|
from = Issue.find_by_id(copied_issues[rel.issue_from.id].id)
|
||
|
next unless from
|
||
|
relation = IssueRelation.new(:issue_from => from, :issue_to => copy, :relation_type => rel.relation_type)
|
||
|
unless relation.save
|
||
|
logger.error "Could not create relation while copying ##{child.id} to ##{copy.id} due to validation errors: #{relation.errors.full_messages.join(', ')}" if logger
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
@after_create_from_copy_handled = true
|
||