diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index b7d8380348..d8660aaf37 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -482,6 +482,11 @@ 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?
+ last_assignee = @issue.last_assigned_to
+ s << content_tag('option', "<< #{l(:label_last_assignee, name: last_assignee.name)} >>", value: last_assignee.id) if last_assignee && last_assignee != User.current && collection.include?(last_assignee)
+ end
groups = ''
collection.sort.each do |element|
selected_attribute = ' selected="selected"' if option_value_selected?(element, selected) || element.id.to_s == selected
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 114d962081..23a53e110b 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -866,6 +866,14 @@ class Issue < ActiveRecord::Base
result
end
+ # Returns the last assignee from the issue history
+ def last_assigned_to
+ journals.reverse_each do |j|
+ last_assignee_change = j.detail_for_attribute 'assigned_to_id'
+ return User.find_by(id: last_assignee_change.old_value.to_i) if last_assignee_change && last_assignee_change.old_value
+ end
+ 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 d8f09431f0..4a38513080 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -839,6 +839,7 @@ en:
label_disabled: disabled
label_show_completed_versions: Show completed versions
label_me: me
+ label_last_assignee: "Last: %{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 aa403be460..91cf5dd52e 100644
--- a/test/helpers/application_helper_test.rb
+++ b/test/helpers/application_helper_test.rb
@@ -1568,6 +1568,36 @@ RAW
assert_include '', principals_options_for_select(users)
end
+ def test_principals_options_for_select_should_include_last_assignee_option_when_last_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 last assignee is not in collection
+ assert_not_include 'Last:', principals_options_for_select([User.find(3)])
+ # when last assignee is not in collection
+ assert_include '', principals_options_for_select(users)
+ end
+
+ def test_principals_options_for_select_should_include_last_assignee_option_when_last_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 last_assignee is current user
+ User.current = User.find(2)
+ assert_not_include 'Last:', principals_options_for_select(users)
+ # when last_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 40be6b66a7..1c89807abe 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -2990,6 +2990,15 @@ class IssueTest < ActiveSupport::TestCase
assert_equal was_closed_on, issue.closed_on
end
+ def test_last_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.last_assigned_to
+ end
+
def test_status_was_should_return_nil_for_new_issue
issue = Issue.new
assert_nil issue.status_was