From 1479b01e49a04e6b7940dbd059450f0a1e70a564 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Fri, 28 Mar 2025 05:32:32 +0000 Subject: [PATCH] Merged r23573 from trunk to 5.1-stable (#42458). git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@23580 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/views/queries/_form.html.erb | 2 +- test/functional/queries_controller_test.rb | 40 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/views/queries/_form.html.erb b/app/views/queries/_form.html.erb index 1c302fe76..75a20248a 100644 --- a/app/views/queries/_form.html.erb +++ b/app/views/queries/_form.html.erb @@ -30,7 +30,7 @@ <% unless @query.is_a?(ProjectQuery) %>

- <%= check_box_tag 'query_is_for_all', 1, @query.project.nil?, :class => (User.current.admin? ? '' : 'disable-unless-private') %>

+ <%= check_box_tag 'query_is_for_all', 1, @query.project.nil?, :disabled => (!@query.new_record? && @query.project.nil?), :class => (User.current.admin? ? '' : 'disable-unless-private') %>

<% end %> <% unless params[:calendar] %> diff --git a/test/functional/queries_controller_test.rb b/test/functional/queries_controller_test.rb index 4ee2155ff..ab3dcf531 100644 --- a/test/functional/queries_controller_test.rb +++ b/test/functional/queries_controller_test.rb @@ -986,4 +986,44 @@ class QueriesControllerTest < Redmine::ControllerTest assert_include ["Development", "10"], json assert_include ["Inactive Activity", "14"], json end + + def test_new_query_is_for_all_checkbox_not_disabled + @request.session[:user_id] = 1 + get :new + assert_response :success + # Verify that the "For all projects" checkbox is not disabled when creating a new query + assert_select 'input[name=query_is_for_all][type=checkbox][checked]:not([disabled])' + end + + def test_new_project_query_is_for_all_checkbox_not_disabled + @request.session[:user_id] = 1 + get(:new, :params => {:project_id => 1}) + assert_response :success + # Verify that the checkbox is not disabled when creating a new query within a project + assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked]):not([disabled])' + end + + def test_edit_global_query_is_for_all_checkbox_disabled + @request.session[:user_id] = 1 + # Create a global query (project_id = nil) + query = IssueQuery.create!(:name => 'test_global_query', :user_id => 1, :project_id => nil) + + get(:edit, :params => {:id => query.id}) + assert_response :success + + # Verify that the "For all projects" checkbox is disabled when editing an existing global query + assert_select 'input[name=query_is_for_all][type=checkbox][checked][disabled]' + end + + def test_edit_project_query_is_for_all_checkbox_not_disabled + @request.session[:user_id] = 1 + # Create a project-specific query + query = IssueQuery.create!(:name => 'test_project_query', :user_id => 1, :project_id => 1) + + get(:edit, :params => {:id => query.id}) + assert_response :success + + # Verify that the checkbox is not disabled when editing a project-specific query + assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked]):not([disabled])' + end end