Adds a "Copied from/to" relation when copying issue(s) (#6899).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10491 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2012-09-27 19:09:30 +00:00
parent c3e055bd70
commit cc4cff9f11
6 changed files with 61 additions and 5 deletions
+13 -4
View File
@@ -1011,11 +1011,20 @@ class Issue < ActiveRecord::Base
end
end
# Copies subtasks from the copied issue
# Callback for after the creation of an issue by copy
# * adds a "copied to" relation with the copied issue
# * copies subtasks from the copied issue
def after_create_from_copy
return unless copy?
return unless copy? && !@after_create_from_copy_handled
unless @copied_from.leaf? || @copy_options[:subtasks] == false || @subtasks_copied
if @copied_from.project_id == project_id || Setting.cross_project_issue_relations?
relation = IssueRelation.new(:issue_from => @copied_from, :issue_to => self, :relation_type => IssueRelation::TYPE_COPIED_TO)
unless relation.save
logger.error "Could not create relation while copying ##{@copied_from.id} to ##{id} due to validation errors: #{relation.errors.full_messages.join(', ')}" if logger
end
end
unless @copied_from.leaf? || @copy_options[:subtasks] == false
@copied_from.children.each do |child|
unless child.visible?
# Do not copy subtasks that are not visible to avoid potential disclosure of private data
@@ -1031,8 +1040,8 @@ class Issue < ActiveRecord::Base
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
end
end
@subtasks_copied = true
end
@after_create_from_copy_handled = true
end
def update_nested_set_attributes
+5 -1
View File
@@ -26,6 +26,8 @@ class IssueRelation < ActiveRecord::Base
TYPE_BLOCKED = "blocked"
TYPE_PRECEDES = "precedes"
TYPE_FOLLOWS = "follows"
TYPE_COPIED_TO = "copied_to"
TYPE_COPIED_FROM = "copied_from"
TYPES = { TYPE_RELATES => { :name => :label_relates_to, :sym_name => :label_relates_to, :order => 1, :sym => TYPE_RELATES },
TYPE_DUPLICATES => { :name => :label_duplicates, :sym_name => :label_duplicated_by, :order => 2, :sym => TYPE_DUPLICATED },
@@ -33,7 +35,9 @@ class IssueRelation < ActiveRecord::Base
TYPE_BLOCKS => { :name => :label_blocks, :sym_name => :label_blocked_by, :order => 4, :sym => TYPE_BLOCKED },
TYPE_BLOCKED => { :name => :label_blocked_by, :sym_name => :label_blocks, :order => 5, :sym => TYPE_BLOCKS, :reverse => TYPE_BLOCKS },
TYPE_PRECEDES => { :name => :label_precedes, :sym_name => :label_follows, :order => 6, :sym => TYPE_FOLLOWS },
TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES }
TYPE_FOLLOWS => { :name => :label_follows, :sym_name => :label_precedes, :order => 7, :sym => TYPE_PRECEDES, :reverse => TYPE_PRECEDES },
TYPE_COPIED_TO => { :name => :label_copied_to, :sym_name => :label_copied_from, :order => 8, :sym => TYPE_COPIED_FROM },
TYPE_COPIED_FROM => { :name => :label_copied_from, :sym_name => :label_copied_to, :order => 9, :sym => TYPE_COPIED_TO, :reverse => TYPE_COPIED_TO }
}.freeze
validates_presence_of :issue_from, :issue_to, :relation_type