diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-03 10:30:29 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-04-03 10:30:29 +0000 |
commit | 756a102820968a1ef7f0fbc4a79a0937f4f9867d (patch) | |
tree | c79f035319d02aaabd64f074ae694705f51d82d3 | |
parent | 2879071f3b73e597b8b0eca490e8710a9de8dbca (diff) | |
download | redmine-756a102820968a1ef7f0fbc4a79a0937f4f9867d.tar.gz redmine-756a102820968a1ef7f0fbc4a79a0937f4f9867d.zip |
Reset status when copying issues (#23610).
git-svn-id: http://svn.redmine.org/redmine/trunk@16451 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/issue.rb | 10 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | test/fixtures/workflows.yml | 7 | ||||
-rw-r--r-- | test/functional/issues_controller_test.rb | 2 | ||||
-rw-r--r-- | test/unit/issue_test.rb | 12 |
5 files changed, 19 insertions, 14 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index 6141780a5..d7ef5eded 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 942affe11..3d8878ca2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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= diff --git a/test/fixtures/workflows.yml b/test/fixtures/workflows.yml index c6ae675fa..b249c948d 100644 --- a/test/fixtures/workflows.yml +++ b/test/fixtures/workflows.yml @@ -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 diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 10ed24c1c..a6f7cd13a 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -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 diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 60ba42f80..36cbc6dcb 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -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 |