From df7ed708d13c0f2247c0d36f3c18ddc95bb16ef0 Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Mon, 27 Apr 2026 12:47:15 +0900 Subject: [PATCH] Add setting to always include issue authors in assignee list --- app/models/issue.rb | 4 ++- app/views/settings/_issues.html.erb | 2 ++ config/locales/en.yml | 1 + config/settings.yml | 2 ++ .../20090318181151_extend_settings_name.rb | 8 +++-- ...hor_to_assignable_users_is_stored_in_db.rb | 13 ++++++++ test/functional/versions_controller_test.rb | 4 ++- test/unit/issue_test.rb | 33 ++++++++++++++----- test/unit/query_test.rb | 5 ++- 9 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20260817090000_ensure_always_add_issue_author_to_assignable_users_is_stored_in_db.rb diff --git a/app/models/issue.rb b/app/models/issue.rb index fa2d7707d..c8d782d6b 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1030,7 +1030,9 @@ class Issue < ApplicationRecord return [] if project.nil? users = project.assignable_users(tracker).to_a - users << author if author && author.active? + if Setting.always_add_issue_author_to_assignable_users? && author&.active? + users << author + end if assigned_to_id_was.present? && assignee = Principal.find_by_id(assigned_to_id_was) users << assignee end diff --git a/app/views/settings/_issues.html.erb b/app/views/settings/_issues.html.erb index b9acf4fda..9665d5951 100644 --- a/app/views/settings/_issues.html.erb +++ b/app/views/settings/_issues.html.erb @@ -15,6 +15,8 @@

<%= setting_select :assignee_dropdown_display_format, assignee_dropdown_display_format_options %>

+

<%= setting_check_box :always_add_issue_author_to_assignable_users %>

+

<%= setting_check_box :default_issue_start_date_to_creation_date %>

<% diff --git a/config/locales/en.yml b/config/locales/en.yml index 6ebe23d46..e01cf0992 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -501,6 +501,7 @@ en: setting_gantt_months_limit: Maximum number of months displayed on the gantt chart setting_issue_group_assignment: Allow issue assignment to groups setting_assignee_dropdown_display_format: Assignee drop-down display format + setting_always_add_issue_author_to_assignable_users: Always allow issue assignment to the author setting_default_issue_start_date_to_creation_date: Use current date as start date for new issues setting_commit_cross_project_ref: Allow issues of all the other projects to be referenced and fixed setting_unsubscribe: Allow users to delete their own account diff --git a/config/settings.yml b/config/settings.yml index 667a4427f..aeb235f8d 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -198,6 +198,8 @@ issue_group_assignment: default: 0 assignee_dropdown_display_format: default: users_then_groups +always_add_issue_author_to_assignable_users: + default: 0 default_issue_start_date_to_creation_date: default: 0 default_issue_due_date_offset: diff --git a/db/migrate/20090318181151_extend_settings_name.rb b/db/migrate/20090318181151_extend_settings_name.rb index 1e4142e78..1b8f669cd 100644 --- a/db/migrate/20090318181151_extend_settings_name.rb +++ b/db/migrate/20090318181151_extend_settings_name.rb @@ -2,14 +2,18 @@ class ExtendSettingsName < ActiveRecord::Migration[4.2] def self.up change_column :settings, :name, :string, :limit => 255, :default => '', :null => false - # This setting is a default setting for new installations. It should be + # These settings are default settings for new installations. They should be # inserted in 017_create_settings.rb with the other default settings, but - # its name exceeds the original 30-character limit of the settings.name + # their names exceed the original 30-character limit of the settings.name # column. Setting.create!( :name => 'default_issue_start_date_to_creation_date', :value => Setting.default_issue_start_date_to_creation_date ) + Setting.create!( + :name => 'always_add_issue_author_to_assignable_users', + :value => Setting.always_add_issue_author_to_assignable_users + ) end def self.down diff --git a/db/migrate/20260817090000_ensure_always_add_issue_author_to_assignable_users_is_stored_in_db.rb b/db/migrate/20260817090000_ensure_always_add_issue_author_to_assignable_users_is_stored_in_db.rb new file mode 100644 index 000000000..d4b24cb7a --- /dev/null +++ b/db/migrate/20260817090000_ensure_always_add_issue_author_to_assignable_users_is_stored_in_db.rb @@ -0,0 +1,13 @@ +class EnsureAlwaysAddIssueAuthorToAssignableUsersIsStoredInDb < ActiveRecord::Migration[8.1] + def up + # Preserve the previous behavior of existing installations, where the issue + # author was always included in the assignee list. + Setting.find_or_create_by!(name: 'always_add_issue_author_to_assignable_users') do |setting| + setting.value = '1' + end + end + + def down + # no-op + end +end diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb index 382b555f9..aa9274d75 100644 --- a/test/functional/versions_controller_test.rb +++ b/test/functional/versions_controller_test.rb @@ -100,7 +100,9 @@ class VersionsControllerTest < Redmine::ControllerTest def test_index_should_show_issue_assignee with_settings :gravatar_enabled => '1' do - Issue.generate!(:project_id => 3, :fixed_version_id => 4, :assigned_to => User.find_by_login('jsmith')) + assignee = User.find_by_login('jsmith') + User.add_to_project(assignee, Project.find(3), Role.find(1)) + Issue.generate!(:project_id => 3, :fixed_version_id => 4, :assigned_to => assignee) Issue.generate!(:project_id => 3, :fixed_version_id => 4) get :index, :params => {:project_id => 3} diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index cc92b8f8e..1f12fee91 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -2696,17 +2696,28 @@ class IssueTest < ActiveSupport::TestCase assert_kind_of User, Issue.find(1).assignable_users.first end - test "#assignable_users should include the issue author" do + test "#assignable_users should include the issue author when enabled by settings" do non_project_member = User.generate! issue = Issue.generate!(:author => non_project_member) - assert issue.assignable_users.include?(non_project_member) + with_settings :always_add_issue_author_to_assignable_users => '1' do + assert issue.assignable_users.include?(non_project_member) + end + end + + test "#assignable_users should not include non member author" do + non_project_member = User.generate! + issue = Issue.generate!(:author => non_project_member) + + assert_not_include non_project_member, issue.assignable_users end def test_assignable_users_should_not_include_anonymous_user issue = Issue.generate!(:author => User.anonymous) - assert !issue.assignable_users.include?(User.anonymous) + with_settings :always_add_issue_author_to_assignable_users => '1' do + assert !issue.assignable_users.include?(User.anonymous) + end end def test_assignable_users_should_not_include_locked_user @@ -2714,7 +2725,9 @@ class IssueTest < ActiveSupport::TestCase issue = Issue.generate!(:author => user) user.lock! - assert !issue.assignable_users.include?(user) + with_settings :always_add_issue_author_to_assignable_users => '1' do + assert !issue.assignable_users.include?(user) + end end def test_assignable_users_should_include_the_current_assignee @@ -2727,12 +2740,14 @@ class IssueTest < ActiveSupport::TestCase end test "#assignable_users should not show the issue author twice" do - assignable_user_ids = Issue.find(1).assignable_users.collect(&:id) - assert_equal 2, assignable_user_ids.length + with_settings :always_add_issue_author_to_assignable_users => '1' do + assignable_user_ids = Issue.find(1).assignable_users.collect(&:id) + assert_equal 2, assignable_user_ids.length - assignable_user_ids.each do |user_id| - assert_equal 1, assignable_user_ids.count {|i| i == user_id}, - "User #{user_id} appears more or less than once" + assignable_user_ids.each do |user_id| + assert_equal 1, assignable_user_ids.count {|i| i == user_id}, + "User #{user_id} appears more or less than once" + end end end diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index ebf7fc991..3d2267743 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -3015,7 +3015,10 @@ class QueryTest < ActiveSupport::TestCase @issue1 = Issue.generate!(:project => @project, :assigned_to_id => @manager.id) @issue2 = Issue.generate!(:project => @project, :assigned_to_id => @developer.id) @issue3 = Issue.generate!(:project => @project, :assigned_to_id => @boss.id) - @issue4 = Issue.generate!(:project => @project, :author_id => @guest.id, :assigned_to_id => @guest.id) + @issue4 = + with_settings :always_add_issue_author_to_assignable_users => '1' do + Issue.generate!(:project => @project, :author_id => @guest.id, :assigned_to_id => @guest.id) + end @issue5 = Issue.generate!(:project => @project) @query = IssueQuery.new(:name => '_', :project => @project) -- 2.50.1