From 28c231473f98a4b184204dd53cbeee1e0d655853 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Thu, 4 Oct 2018 12:46:32 +0000 Subject: [PATCH] Custom queries are broken by updating with nil parameter values (#29701). Patch by Mizuki ISHIKAWA. git-svn-id: http://svn.redmine.org/redmine/trunk@17566 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/queries_controller.rb | 2 +- app/models/issue_query.rb | 4 ++-- app/models/query.rb | 8 ++++---- test/unit/query_test.rb | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/controllers/queries_controller.rb b/app/controllers/queries_controller.rb index 647d322ed..784dec984 100644 --- a/app/controllers/queries_controller.rb +++ b/app/controllers/queries_controller.rb @@ -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 diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index c342dc456..38946f75a 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -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 diff --git a/app/models/query.rb b/app/models/query.rb index 2c0f90161..8bb391e66 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -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 diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 924a8f4f3..8c530caeb 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -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 -- 2.39.5