diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-09-03 07:21:32 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-09-03 07:21:32 +0000 |
commit | a20458612ef3ada099416b3180e8a2f7d31458b3 (patch) | |
tree | 43acd848869f78569dbd06595d8a2353b17fc13c | |
parent | ddc575564744cbc65600a0aaf92f55ec65570e83 (diff) | |
download | redmine-a20458612ef3ada099416b3180e8a2f7d31458b3.tar.gz redmine-a20458612ef3ada099416b3180e8a2f7d31458b3.zip |
When copying an issue, all statuses for new issue should be available (#14696).
git-svn-id: http://svn.redmine.org/redmine/trunk@15810 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/issue.rb | 69 | ||||
-rw-r--r-- | test/unit/issue_test.rb | 11 |
2 files changed, 41 insertions, 39 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index 6cbb18033..4e32dcec1 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -899,44 +899,45 @@ class Issue < ActiveRecord::Base # Returns an array of statuses that user is able to apply def new_statuses_allowed_to(user=User.current, include_default=false) - if new_record? && @copied_from - [default_status, @copied_from.status].compact.uniq.sort - else - initial_status = nil - if new_record? - # nop - elsif tracker_id_changed? - if Tracker.where(:id => tracker_id_was, :default_status_id => status_id_was).any? - initial_status = default_status - elsif tracker.issue_status_ids.include?(status_id_was) - initial_status = IssueStatus.find_by_id(status_id_was) - else - initial_status = default_status - end + initial_status = nil + if new_record? + # nop + elsif tracker_id_changed? + if Tracker.where(:id => tracker_id_was, :default_status_id => status_id_was).any? + initial_status = default_status + elsif tracker.issue_status_ids.include?(status_id_was) + initial_status = IssueStatus.find_by_id(status_id_was) else - initial_status = status_was + initial_status = default_status end + else + initial_status = status_was + end - initial_assigned_to_id = assigned_to_id_changed? ? assigned_to_id_was : assigned_to_id - assignee_transitions_allowed = initial_assigned_to_id.present? && - (user.id == initial_assigned_to_id || user.group_ids.include?(initial_assigned_to_id)) - - statuses = [] - statuses += IssueStatus.new_statuses_allowed( - initial_status, - user.admin ? Role.all.to_a : user.roles_for_project(project), - tracker, - author == user, - assignee_transitions_allowed - ) - statuses << initial_status unless statuses.empty? - statuses << default_status if include_default || (new_record? && statuses.empty?) - statuses = statuses.compact.uniq.sort - if blocked? - statuses.reject!(&:is_closed?) - end - statuses + initial_assigned_to_id = assigned_to_id_changed? ? assigned_to_id_was : assigned_to_id + assignee_transitions_allowed = initial_assigned_to_id.present? && + (user.id == initial_assigned_to_id || user.group_ids.include?(initial_assigned_to_id)) + + statuses = [] + statuses += IssueStatus.new_statuses_allowed( + initial_status, + user.admin ? Role.all.to_a : user.roles_for_project(project), + tracker, + author == user, + assignee_transitions_allowed + ) + 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? + statuses.reject!(&:is_closed?) end + statuses end # Returns the previous assignee (user or group) if changed diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 8c95023e7..a532001dc 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -775,12 +775,13 @@ class IssueTest < ActiveSupport::TestCase assert_equal expected_statuses, issue.new_statuses_allowed_to(admin) end - def test_new_statuses_allowed_to_should_return_default_and_current_status_when_copying - issue = Issue.find(1).copy - assert_equal [1], issue.new_statuses_allowed_to(User.find(2)).map(&:id) + def test_new_statuses_allowed_to_should_return_allowed_statuses_and_current_status_when_copying + Tracker.find(1).generate_transitions! :role_id => 1, :clear => true, 0 => [1, 3] - issue = Issue.find(2).copy - assert_equal [1, 2], issue.new_statuses_allowed_to(User.find(2)).map(&:id) + 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 end def test_safe_attributes_names_should_not_include_disabled_field |