diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-09-08 05:34:07 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-09-08 05:34:07 +0000 |
commit | 5003927f13f54850ca9eeac48e353df5e4e325a1 (patch) | |
tree | 6af9692d3604e9520af7268f14b728eeed87a120 /app/models/issue.rb | |
parent | ffcf1925e3974e2907aa7baa180bbb2a71952a9d (diff) | |
download | redmine-5003927f13f54850ca9eeac48e353df5e4e325a1.tar.gz redmine-5003927f13f54850ca9eeac48e353df5e4e325a1.zip |
Option to copy subtasks when copying issue(s) (#6965).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10327 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r-- | app/models/issue.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index c7358c0e5..f3851927e 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -77,6 +77,8 @@ class Issue < ActiveRecord::Base before_save :close_duplicates, :update_done_ratio_from_issue_status, :force_updated_on_change after_save {|issue| issue.send :after_project_change if !issue.id_changed? && issue.project_id_changed?} after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal + # Should be after_create but would be called before previous after_save callbacks + after_save :after_create_from_copy after_destroy :update_parent_attributes # Returns a SQL conditions string used to find all issues visible by the specified user @@ -169,6 +171,7 @@ class Issue < ActiveRecord::Base end end @copied_from = issue + @copy_options = options self end @@ -1000,6 +1003,30 @@ class Issue < ActiveRecord::Base end end + # Copies subtasks from the copied issue + def after_create_from_copy + return unless copy? + + unless @copied_from.leaf? || @copy_options[:subtasks] == false || @subtasks_copied + @copied_from.children.each do |child| + 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.author = author + copy.project = project + copy.parent_issue_id = id + # Children subtasks are copied recursively + 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 + end + end + @subtasks_copied = true + end + end + def update_nested_set_attributes if root_id.nil? # issue was just created |