mirror of
https://github.com/redmine/redmine.git
synced 2025-10-26 07:46:17 +01:00
Reset status when copying issues (#23610).
git-svn-id: http://svn.redmine.org/redmine/trunk@16451 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -265,9 +265,11 @@ class Issue < ActiveRecord::Base
|
||||
# Copies attributes from another issue, arg can be an id or an Issue
|
||||
def copy_from(arg, options={})
|
||||
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
|
||||
self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on", "closed_on")
|
||||
self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on", "status_id", "closed_on")
|
||||
self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
||||
self.status = issue.status
|
||||
if options[:keep_status]
|
||||
self.status = issue.status
|
||||
end
|
||||
self.author = User.current
|
||||
unless options[:attachments] == false
|
||||
self.attachments = issue.attachments.map do |attachement|
|
||||
@@ -973,10 +975,6 @@ class Issue < ActiveRecord::Base
|
||||
statuses << initial_status unless statuses.empty?
|
||||
statuses << default_status if include_default || (new_record? && statuses.empty?)
|
||||
|
||||
if new_record? && @copied_from
|
||||
statuses << @copied_from.status
|
||||
end
|
||||
|
||||
statuses = statuses.compact.uniq.sort
|
||||
if blocked? || descendants.open.any?
|
||||
# cannot close a blocked issue or a parent with open subtasks
|
||||
|
||||
@@ -952,7 +952,7 @@ class Project < ActiveRecord::Base
|
||||
# get copied before their children
|
||||
project.issues.reorder('root_id, lft').each do |issue|
|
||||
new_issue = Issue.new
|
||||
new_issue.copy_from(issue, :subtasks => false, :link => false)
|
||||
new_issue.copy_from(issue, :subtasks => false, :link => false, :keep_status => true)
|
||||
new_issue.project = self
|
||||
# Changing project resets the custom field values
|
||||
# TODO: handle this in Issue#project=
|
||||
|
||||
7
test/fixtures/workflows.yml
vendored
7
test/fixtures/workflows.yml
vendored
@@ -1924,3 +1924,10 @@ WorkflowTransitions_276:
|
||||
id: 276
|
||||
tracker_id: 2
|
||||
type: WorkflowTransition
|
||||
WorkflowTransitions_277:
|
||||
new_status_id: 1
|
||||
role_id: 2
|
||||
old_status_id: 0
|
||||
id: 277
|
||||
tracker_id: 1
|
||||
type: WorkflowTransition
|
||||
|
||||
@@ -4581,7 +4581,7 @@ class IssuesControllerTest < Redmine::ControllerTest
|
||||
assert_not_nil copy
|
||||
assert_equal orig.project_id, copy.project_id
|
||||
assert_equal orig.tracker_id, copy.tracker_id
|
||||
assert_equal orig.status_id, copy.status_id
|
||||
assert_equal 1, copy.status_id
|
||||
if orig.assigned_to_id
|
||||
assert_equal orig.assigned_to_id, copy.assigned_to_id
|
||||
else
|
||||
|
||||
@@ -794,13 +794,13 @@ class IssueTest < ActiveSupport::TestCase
|
||||
assert_equal expected_statuses, issue.new_statuses_allowed_to(admin)
|
||||
end
|
||||
|
||||
def test_new_statuses_allowed_to_should_return_allowed_statuses_and_current_status_when_copying
|
||||
def test_new_statuses_allowed_to_should_return_allowed_statuses_when_copying
|
||||
Tracker.find(1).generate_transitions! :role_id => 1, :clear => true, 0 => [1, 3]
|
||||
|
||||
orig = Issue.generate!(:project_id => 1, :tracker_id => 1, :status_id => 4)
|
||||
issue = orig.copy
|
||||
assert_equal [1, 3, 4], issue.new_statuses_allowed_to(User.find(2)).map(&:id)
|
||||
assert_equal 4, issue.status_id
|
||||
assert_equal [1, 3], issue.new_statuses_allowed_to(User.find(2)).map(&:id)
|
||||
assert_equal 1, issue.status_id
|
||||
end
|
||||
|
||||
def test_safe_attributes_names_should_not_include_disabled_field
|
||||
@@ -1225,11 +1225,11 @@ class IssueTest < ActiveSupport::TestCase
|
||||
assert_nil issue.assigned_to
|
||||
end
|
||||
|
||||
def test_copy_should_copy_status
|
||||
def test_copy_with_keep_status_should_copy_status
|
||||
orig = Issue.find(8)
|
||||
assert orig.status != orig.default_status
|
||||
|
||||
issue = Issue.new.copy_from(orig)
|
||||
issue = Issue.new.copy_from(orig, :keep_status => true)
|
||||
assert issue.save
|
||||
issue.reload
|
||||
assert_equal orig.status, issue.status
|
||||
@@ -1331,7 +1331,7 @@ class IssueTest < ActiveSupport::TestCase
|
||||
assert copied_open.save
|
||||
assert_nil copied_open.closed_on
|
||||
|
||||
copied_closed = Issue.find(8).copy
|
||||
copied_closed = Issue.find(8).copy({}, :keep_status => 1)
|
||||
assert copied_closed.save
|
||||
assert_not_nil copied_closed.closed_on
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user