diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index b7d8380348..08997c58b7 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?
+ 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|
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..562c430c1a 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -866,6 +866,14 @@ 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
+ 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..c0bd0190f3 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_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 aa403be460..8401c45e32 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_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 40be6b66a7..98b2449fd1 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_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_status_was_should_return_nil_for_new_issue
issue = Issue.new
assert_nil issue.status_was