diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 3177d0eb7c..fdbca81432 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -646,6 +646,12 @@ module ApplicationHelper
if collection.include?(User.current)
s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id)
end
+ # do not add option in case of bulk and issue category edit
+ unless @issue.nil?
+ previous_assignee = @issue.previous_assigned_to
+ s << content_tag('option', "<< #{l(:label_previous_assignee, name: previous_assignee.name)} >>", value: previous_assignee.id) if previous_assignee && previous_assignee != User.current && collection.include?(previous_assignee)
+ end
+
groups = +''
collection.sort.each do |element|
if option_value_selected?(element, selected) || element.id.to_s == selected
diff --git a/app/models/issue.rb b/app/models/issue.rb
index f267f3f480..aaccade5fa 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -924,6 +924,15 @@ class Issue < ActiveRecord::Base
result
end
+ # Returns the previous assignee from the issue history
+ def previous_assigned_to
+ journals.reverse_each do |j|
+ previous_assignee_change = j.detail_for_attribute 'assigned_to_id'
+ return User.find_by(id: previous_assignee_change.old_value.to_i) if previous_assignee_change && previous_assignee_change.old_value
+ end
+ nil
+ end
+
# Returns the initial status of the issue
# Returns nil for a new issue
def status_was
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 8c9edb8bc9..0fc3caad12 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -898,6 +898,7 @@ en:
label_optional: optional
label_show_completed_versions: Show completed versions
label_me: me
+ label_previous_assignee: "Previous: %{name}"
label_board: Forum
label_board_new: New forum
label_board_plural: Forums
diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb
index ddc55dcb8e..de8834c12c 100644
--- a/test/helpers/application_helper_test.rb
+++ b/test/helpers/application_helper_test.rb
@@ -2035,6 +2035,36 @@ class ApplicationHelperTest < Redmine::HelperTest
principals_options_for_select(users)
end
+ def test_principals_options_for_select_should_include_previous_assignee_option_when_previous_assignee_is_in_collection
+ set_language_if_valid 'en'
+ users = [User.find(2), User.find(3)]
+ @issue = Issue.generate!(assigned_to_id: 2)
+ @issue.init_journal(users.first, 'update')
+ @issue.assigned_to_id = 3
+ @issue.save
+
+ # when previous assignee is not in collection
+ assert_not_include 'Previous:', principals_options_for_select([User.find(3)])
+ # when previous assignee is not in collection
+ assert_include '', principals_options_for_select(users)
+ end
+
+ def test_principals_options_for_select_should_include_previous_assignee_option_when_previous_assignee_is_not_current_user
+ set_language_if_valid 'en'
+ users = [User.find(2), User.find(3)]
+ @issue = Issue.generate!(assigned_to_id: 2)
+ @issue.init_journal(users.first, 'update')
+ @issue.assigned_to_id = 3
+ @issue.save
+
+ # when previous_assignee is current user
+ User.current = User.find(2)
+ assert_not_include 'Previous:', principals_options_for_select(users)
+ # when previous_assignee is not current user
+ User.current = User.find(3)
+ assert_include '', principals_options_for_select(users)
+ end
+
def test_stylesheet_link_tag_should_pick_the_default_stylesheet
assert_match 'href="/stylesheets/styles.css"', stylesheet_link_tag("styles")
end
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index 08bc50df86..6446d44c11 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -3210,6 +3210,24 @@ class IssueTest < ActiveSupport::TestCase
assert_equal was_closed_on, issue.closed_on
end
+ def test_previous_assigned_to
+ issue = Issue.generate!(assigned_to_id: 2)
+ issue.init_journal(User.find(2), 'update')
+ issue.assigned_to_id = 3
+ issue.save
+
+ assert_equal User.find(2), issue.previous_assigned_to
+ end
+
+ def test_previous_assigned_to_should_return_nil
+ issue = Issue.generate!(assigned_to_id: 2)
+ issue.assigned_to_id = 3
+ issue.save
+
+ assert_equal 0, issue.journals.count
+ assert_nil issue.previous_assigned_to
+ end
+
def test_status_was_should_return_nil_for_new_issue
issue = Issue.new
assert_nil issue.status_was