diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a677b80a8..3dd9d77ff 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -672,6 +672,16 @@ 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
+ if @issue.present?
+ prior_assignee = @issue.prior_assigned_to
+ if prior_assignee && prior_assignee != User.current && collection.include?(prior_assignee)
+ s << content_tag('option',
+ "<< #{l(:label_previous_assignee, name: prior_assignee.name)} >>",
+ value: prior_assignee.id)
+ end
+ 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 9b47ce7bd..8dca6ad17 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -925,6 +925,18 @@ class Issue < ApplicationRecord
result
end
+ # Returns the assignee immediately prior to the current one from the issue history
+ def prior_assigned_to
+ prior_assigned_to_id =
+ journals.joins(:details)
+ .where(details: {prop_key: 'assigned_to_id'})
+ .where.not(details: {old_value: nil})
+ .order(id: :desc)
+ .pick(:old_value)
+
+ prior_assigned_to_id && Principal.find_by(id: prior_assigned_to_id)
+ 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 1584f5ef2..5037d3bd1 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -909,6 +909,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 ab0d8f91f..604da05a1 100644
--- a/test/helpers/application_helper_test.rb
+++ b/test/helpers/application_helper_test.rb
@@ -2070,6 +2070,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="/assets/styles.css"', stylesheet_link_tag("styles")
end
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index 7480fbc55..7566a4561 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -3247,6 +3247,24 @@ class IssueTest < ActiveSupport::TestCase
assert_equal was_closed_on, issue.closed_on
end
+ def test_prior_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.prior_assigned_to
+ end
+
+ def test_prior_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.prior_assigned_to
+ end
+
def test_status_was_should_return_nil_for_new_issue
issue = Issue.new
assert_nil issue.status_was