Project

General

Profile

Defect #29701 » bugfix-29701.patch

Mizuki ISHIKAWA, 2018-10-04 03:49

View differences:

app/controllers/queries_controller.rb
122 122
    @query.project = params[:query_is_for_all] ? nil : @project
123 123
    @query.build_from_params(params)
124 124
    @query.column_names = nil if params[:default_columns]
125
    @query.sort_criteria = params[:query] && params[:query][:sort_criteria]
125
    @query.sort_criteria = (params[:query] && params[:query][:sort_criteria]) || @query.sort_criteria
126 126
    @query.name = params[:query] && params[:query][:name]
127 127
    if User.current.allowed_to?(:manage_public_queries, @query.project) || User.current.admin?
128 128
      @query.visibility = (params[:query] && params[:query][:visibility]) || Query::VISIBILITY_PRIVATE
app/models/issue_query.rb
75 75

  
76 76
  def build_from_params(params, defaults={})
77 77
    super
78
    self.draw_relations = params[:draw_relations] || (params[:query] && params[:query][:draw_relations])
79
    self.draw_progress_line = params[:draw_progress_line] || (params[:query] && params[:query][:draw_progress_line])
78
    self.draw_relations = params[:draw_relations] || (params[:query] && params[:query][:draw_relations]) || options[:draw_relations]
79
    self.draw_progress_line = params[:draw_progress_line] || (params[:query] && params[:query][:draw_progress_line]) || options[:draw_progress_line]
80 80
    self
81 81
  end
82 82

  
app/models/query.rb
377 377
    end
378 378

  
379 379
    query_params = params[:query] || defaults || {}
380
    self.group_by = params[:group_by] || query_params[:group_by]
381
    self.column_names = params[:c] || query_params[:column_names]
382
    self.totalable_names = params[:t] || query_params[:totalable_names]
383
    self.sort_criteria = params[:sort] || query_params[:sort_criteria]
380
    self.group_by = params[:group_by] || query_params[:group_by] || self.group_by
381
    self.column_names = params[:c] || query_params[:column_names] || self.column_names
382
    self.totalable_names = params[:t] || query_params[:totalable_names] || self.totalable_names
383
    self.sort_criteria = params[:sort] || query_params[:sort_criteria] || self.sort_criteria
384 384
    self
385 385
  end
386 386

  
test/unit/query_test.rb
1873 1873
    assert_nil IssueQuery.visible(User.find(1)).find_by_id(q.id)
1874 1874
  end
1875 1875

  
1876
  def test_build_from_params_should_not_overwrite_with_unspecified_parameters
1877
    q = IssueQuery.create!(:name => 'Query',
1878
                           :type => "IssueQuery",
1879
                           :user => User.find(7),
1880
                           :filters => {"status_id" => {:values => ["1"], :operator => "o"}},
1881
                           :column_names => [:tracker, :status],
1882
                           :sort_criteria => ['id', 'asc'],
1883
                           :group_by => "project",
1884
                           :options => { :totalable_names=>[:estimated_hours], :draw_relations => '1', :draw_progress_line => '1' }
1885
                            )
1886
    old_attributes = q.attributes
1887
    q.build_from_params({})
1888
    assert_equal old_attributes, q.attributes
1889
  end
1890

  
1876 1891
  test "#available_filters should include users of visible projects in cross-project view" do
1877 1892
    users = IssueQuery.new.available_filters["assigned_to_id"]
1878 1893
    assert_not_nil users
(4-4/4)