From ab2f00f2ebf34931f6fa9e67751535bb6cb0b728 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 28 Apr 2024 07:12:32 +0000 Subject: [PATCH] Fixes that watcher groups on new issue form get dereferenced on validation error (#40410, #40555). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Patch by Felix Schäfer (@felix) and Kenta Kumojima (@kumojima). git-svn-id: https://svn.redmine.org/redmine/trunk@22792 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/watchers_helper.rb | 2 +- test/functional/issues_controller_test.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index d01d4858d..c9d14d95f 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -74,7 +74,7 @@ module WatchersHelper def watchers_checkboxes(object, users, checked=nil) users.map do |user| - c = checked.nil? ? object.watched_by?(user) : checked + c = checked.nil? ? object.watcher_user_ids.include?(user.id) : checked tag = check_box_tag 'issue[watcher_user_ids][]', user.id, c, :id => nil content_tag 'label', "#{tag} #{h(user)}".html_safe, :id => "issue_watcher_user_ids_#{user.id}", diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index cce8ddc62..014a2d835 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -4778,6 +4778,24 @@ class IssuesControllerTest < Redmine::ControllerTest assert_select 'input[name=?][value="8"][checked=checked]', 'issue[watcher_user_ids][]' end + def test_post_create_with_failure_should_not_dereference_group_watchers + @request.session[:user_id] = 1 + post( + :create, + :params => { + :project_id => 5, + :issue => { + :tracker_id => 1, + :watcher_user_ids => ['11'] + } + } + ) + assert_response :success + + assert_select 'input[name=?][value="8"][checked=checked]', 'issue[watcher_user_ids][]', 0 + assert_select 'input[name=?][value="11"][checked=checked]', 'issue[watcher_user_ids][]', 1 + end + def test_post_create_should_ignore_non_safe_attributes @request.session[:user_id] = 2 assert_nothing_raised do -- 2.39.5