]> source.dussan.org Git - redmine.git/commitdiff
Custom queries are broken by updating with nil parameter values (#29701).
authorGo MAEDA <maeda@farend.jp>
Thu, 4 Oct 2018 12:46:32 +0000 (12:46 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 4 Oct 2018 12:46:32 +0000 (12:46 +0000)
Patch by Mizuki ISHIKAWA.

git-svn-id: http://svn.redmine.org/redmine/trunk@17566 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/queries_controller.rb
app/models/issue_query.rb
app/models/query.rb
test/unit/query_test.rb

index 647d322ed1b7ca061dcb0e556a8f583443aa16fb..784dec984096d704f495c62b67b8915dd85dfc62 100644 (file)
@@ -122,7 +122,7 @@ class QueriesController < ApplicationController
     @query.project = params[:query_is_for_all] ? nil : @project
     @query.build_from_params(params)
     @query.column_names = nil if params[:default_columns]
-    @query.sort_criteria = params[:query] && params[:query][:sort_criteria]
+    @query.sort_criteria = (params[:query] && params[:query][:sort_criteria]) || @query.sort_criteria
     @query.name = params[:query] && params[:query][:name]
     if User.current.allowed_to?(:manage_public_queries, @query.project) || User.current.admin?
       @query.visibility = (params[:query] && params[:query][:visibility]) || Query::VISIBILITY_PRIVATE
index c342dc4561e467f00738b5148c329f6af6c1f134..38946f75a81ab420c1dfc70c2ba6d6916cecc8db 100644 (file)
@@ -75,8 +75,8 @@ class IssueQuery < Query
 
   def build_from_params(params, defaults={})
     super
-    self.draw_relations = params[:draw_relations] || (params[:query] && params[:query][:draw_relations])
-    self.draw_progress_line = params[:draw_progress_line] || (params[:query] && params[:query][:draw_progress_line])
+    self.draw_relations = params[:draw_relations] || (params[:query] && params[:query][:draw_relations]) || options[:draw_relations]
+    self.draw_progress_line = params[:draw_progress_line] || (params[:query] && params[:query][:draw_progress_line]) || options[:draw_progress_line]
     self
   end
 
index 2c0f90161aad9797823ccbd39d1b024e1d0aefa0..8bb391e66c80e61d1724d403775bd2191cbdf639 100644 (file)
@@ -377,10 +377,10 @@ class Query < ActiveRecord::Base
     end
 
     query_params = params[:query] || defaults || {}
-    self.group_by = params[:group_by] || query_params[:group_by]
-    self.column_names = params[:c] || query_params[:column_names]
-    self.totalable_names = params[:t] || query_params[:totalable_names]
-    self.sort_criteria = params[:sort] || query_params[:sort_criteria]
+    self.group_by = params[:group_by] || query_params[:group_by] || self.group_by
+    self.column_names = params[:c] || query_params[:column_names] || self.column_names
+    self.totalable_names = params[:t] || query_params[:totalable_names] || self.totalable_names
+    self.sort_criteria = params[:sort] || query_params[:sort_criteria] || self.sort_criteria
     self
   end
 
index 924a8f4f38f149a18767df31d1ebda67e278bd92..8c530caeb6c89393735cbce8c89454ff399bea10 100644 (file)
@@ -1873,6 +1873,21 @@ class QueryTest < ActiveSupport::TestCase
     assert_nil IssueQuery.visible(User.find(1)).find_by_id(q.id)
   end
 
+  def test_build_from_params_should_not_update_query_with_nil_param_values
+    q = IssueQuery.create!(:name => 'Query',
+                           :type => "IssueQuery",
+                           :user => User.find(7),
+                           :filters => {"status_id" => {:values => ["1"], :operator => "o"}},
+                           :column_names => [:tracker, :status],
+                           :sort_criteria => ['id', 'asc'],
+                           :group_by => "project",
+                           :options => { :totalable_names=>[:estimated_hours], :draw_relations => '1', :draw_progress_line => '1' }
+                            )
+    old_attributes = q.attributes
+    q.build_from_params({})
+    assert_equal old_attributes, q.attributes
+  end
+
   test "#available_filters should include users of visible projects in cross-project view" do
     users = IssueQuery.new.available_filters["assigned_to_id"]
     assert_not_nil users