summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2025-03-27 01:07:48 +0000
committerGo MAEDA <maeda@farend.jp>2025-03-27 01:07:48 +0000
commite0e0be492894d958a1fff6533465123889c6eff8 (patch)
treed8eeb97f3a0fca949ace8c3871a4838843b0f129
parentc866aa74d84c2aaf69e03c05903c1cd0da9ba67b (diff)
downloadredmine-e0e0be492894d958a1fff6533465123889c6eff8.tar.gz
redmine-e0e0be492894d958a1fff6533465123889c6eff8.zip
"For all projects" checkbox should be disabled when editing an existing query in which the checkbox is already checked (#42458).
Patch by [Agileware] nusohiro (user:nusohiro). git-svn-id: https://svn.redmine.org/redmine/trunk@23573 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/views/queries/_form.html.erb2
-rw-r--r--test/functional/queries_controller_test.rb40
2 files changed, 41 insertions, 1 deletions
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) %>
<p><label for="query_is_for_all"><%=l(:field_is_for_all)%></label>
- <%= check_box_tag 'query_is_for_all', 1, @query.project.nil?, :class => (User.current.admin? ? '' : 'disable-unless-private') %></p>
+ <%= 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') %></p>
<% end %>
<% unless params[:calendar] %>
diff --git a/test/functional/queries_controller_test.rb b/test/functional/queries_controller_test.rb
index 7f446f2b4..4f0827da8 100644
--- a/test/functional/queries_controller_test.rb
+++ b/test/functional/queries_controller_test.rb
@@ -1030,4 +1030,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