Commit 421a9c6b authored by jplang's avatar jplang

When copying an issue, all statuses for new issue should be available (#14696).

git-svn-id: https://svn.redmine.org/redmine/trunk@15810 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent b40fb03d
......@@ -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
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment