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
This commit is contained in:
@@ -221,6 +221,7 @@ class IssuesController < ApplicationController
|
||||
@categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
|
||||
if @copy
|
||||
@attachments_present = @issues.detect {|i| i.attachments.any?}.present?
|
||||
@subtasks_present = @issues.detect {|i| !i.leaf?}.present?
|
||||
end
|
||||
|
||||
@safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
|
||||
@@ -237,7 +238,10 @@ class IssuesController < ApplicationController
|
||||
@issues.each do |issue|
|
||||
issue.reload
|
||||
if @copy
|
||||
issue = issue.copy({}, :attachments => params[:copy_attachments].present?)
|
||||
issue = issue.copy({},
|
||||
:attachments => params[:copy_attachments].present?,
|
||||
:subtasks => params[:copy_subtasks].present?
|
||||
)
|
||||
end
|
||||
journal = issue.init_journal(User.current, params[:notes])
|
||||
issue.safe_attributes = attributes
|
||||
@@ -374,7 +378,8 @@ private
|
||||
begin
|
||||
@copy_from = Issue.visible.find(params[:copy_from])
|
||||
@copy_attachments = params[:copy_attachments].present? || request.get?
|
||||
@issue.copy_from(@copy_from, :attachments => @copy_attachments)
|
||||
@copy_subtasks = params[:copy_subtasks].present? || request.get?
|
||||
@issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
return
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -77,6 +77,13 @@
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<% if @copy && @subtasks_present %>
|
||||
<p>
|
||||
<label for='copy_subtasks'><%= l(:label_copy_subtasks) %></label>
|
||||
<%= check_box_tag 'copy_subtasks', '1', true %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -17,6 +17,12 @@
|
||||
<%= check_box_tag 'copy_attachments', '1', @copy_attachments %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% if @copy_from && !@copy_from.leaf? %>
|
||||
<p>
|
||||
<label for="copy_subtasks"><%= l(:label_copy_subtasks) %></label>
|
||||
<%= check_box_tag 'copy_subtasks', '1', @copy_subtasks %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<p id="attachments_form"><label><%= l(:label_attachment_plural) %></label><%= render :partial => 'attachments/form', :locals => {:container => @issue} %></p>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user