From 759976ad25a25dec49c314f0963ece0b7a5aba9c Mon Sep 17 00:00:00 2001 Date: Wed, 19 Mar 2025 12:57:35 +0900 Subject: [PATCH 1/2] fix: disable "For all projects" checkbox for existing queries --- app/views/queries/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/queries/_form.html.erb b/app/views/queries/_form.html.erb index b70ef53df..8b52383de 100644 --- a/app/views/queries/_form.html.erb +++ b/app/views/queries/_form.html.erb @@ -32,7 +32,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] %> -- 2.45.2 From b2d963d654f4366f5095d188144fe4245ca5f5e5 Mon Sep 17 00:00:00 2001 Date: Wed, 19 Mar 2025 13:38:47 +0900 Subject: [PATCH 2/2] test: add tests for "For all projects" checkbox disabled state --- .../queries_controller_is_for_all_test.rb | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/functional/queries_controller_is_for_all_test.rb diff --git a/test/functional/queries_controller_is_for_all_test.rb b/test/functional/queries_controller_is_for_all_test.rb new file mode 100644 index 000000000..eae613e05 --- /dev/null +++ b/test/functional/queries_controller_is_for_all_test.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006- Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require_relative '../test_helper' + +class QueriesControllerIsForAllTest < Redmine::ControllerTest + fixtures :projects, :users, :roles, :members, :member_roles, :issues, :issue_statuses, :trackers, + :enumerations, :custom_fields, :custom_values, :custom_fields_trackers, :queries + + def setup + User.current = nil + @request.session[:user_id] = 1 # admin + @controller = QueriesController.new + end + + def test_new_query_is_for_all_checkbox_not_disabled + 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 + 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 + # 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 + # 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 -- 2.45.2