diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-03-01 12:26:06 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-03-01 12:26:06 +0000 |
commit | caf61dc923cf351743610f5a6540ac8f534c1e05 (patch) | |
tree | 09c735865a4484acbdddf8bfcc158321855d9c83 /app/models/issue.rb | |
parent | 4185a4ae3b1a6f9592dc4c80a37875e4c57347f2 (diff) | |
download | redmine-caf61dc923cf351743610f5a6540ac8f534c1e05.tar.gz redmine-caf61dc923cf351743610f5a6540ac8f534c1e05.zip |
Fixed that copying an issue as a child of itself creates an extra issue (#13328).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11513 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r-- | app/models/issue.rb | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index 5ec33a3df..96e0326e2 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1147,20 +1147,27 @@ class Issue < ActiveRecord::Base end unless @copied_from.leaf? || @copy_options[:subtasks] == false - @copied_from.children.each do |child| + copy_options = (@copy_options || {}).merge(:subtasks => false) + copied_issue_ids = {@copied_from.id => self.id} + @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] + # Do not copy subtasks that are not visible to avoid potential disclosure of private data unless child.visible? - # Do not copy subtasks that are not visible to avoid potential disclosure of private data logger.error "Subtask ##{child.id} was not copied during ##{@copied_from.id} copy because it is not visible to the current user" if logger next end - copy = Issue.new.copy_from(child, @copy_options) + copy = Issue.new.copy_from(child, copy_options) copy.author = author copy.project = project - copy.parent_issue_id = id - # Children subtasks are copied recursively + copy.parent_issue_id = copied_issue_ids[child.parent_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 end end @after_create_from_copy_handled = true |