fix-37499.patch

Mizuki ISHIKAWA, 2022-07-28 06:54

Download (6.23 KB)

View differences:

app/models/issue_query.rb
78 78
  scope :for_all_projects, ->{ where(project_id: nil) }
79 79

  
80 80
  def self.default(project: nil, user: User.current)
81
    query = nil
82 81
    # user default
83 82
    if user&.logged? && (query_id = user.pref.default_issue_query).present?
84 83
      query = find_by(id: query_id)
84
      return query if query&.visible?
85 85
    end
86

  
86 87
    # project default
87
    query ||= project&.default_issue_query
88
    query = project&.default_issue_query
89
    return query if query&.visibility == VISIBILITY_PUBLIC
90

  
88 91
    # global default
89
    if query.nil? && (query_id = Setting.default_issue_query).present?
92
    if (query_id = Setting.default_issue_query).present?
90 93
      query = find_by(id: query_id)
94
      return query if query&.visibility == VISIBILITY_PUBLIC
91 95
    end
92
    query
96
    nil
93 97
  end
94 98

  
95 99
  def initialize(attributes=nil, *args)
app/models/project_query.rb
40 40
  ]
41 41

  
42 42
  def self.default(project: nil, user: User.current)
43
    query = nil
44 43
    if user&.logged? && (query_id = user.pref.default_project_query).present?
45 44
      query = find_by(id: query_id)
45
      return query if query&.visible?
46 46
    end
47 47
    if query.nil? && (query_id = Setting.default_project_query).present?
48 48
      query = find_by(id: query_id)
49
      return query if query&.visibility == VISIBILITY_PUBLIC
49 50
    end
50
    query
51
    nil
51 52
  end
52 53

  
53 54
  def initialize(attributes=nil, *args)
test/functional/issues_controller_test.rb
8482 8482
    # query filters for tracker_id == 3
8483 8483
    assert results.detect{ |i| i['tracker_id'] != 3 }
8484 8484
  end
8485

  
8486
  def test_index_should_only_use_user_default_query_for_users_who_have_default_query_available
8487
    query = IssueQuery.find(4)
8488

  
8489
    query.update(visibility: Query::VISIBILITY_PRIVATE, user_id: 2)
8490
    query.save!
8491

  
8492
    # If visible default query
8493
    @request.session[:user_id] = 2
8494
    @request.session[:issue_query] = nil
8495
    User.find(2).pref.update(default_issue_query: query.id)
8496
    get :index
8497
    assert_select 'h2', text: query.name
8498

  
8499
    # If invisible default query
8500
    @request.session[:user_id] = 3
8501
    @request.session[:issue_query] = nil
8502
    User.find(3).pref.update(default_issue_query: query.id)
8503
    get :index
8504
    assert_select 'h2', text: 'Issues'
8505
  end
8506

  
8507
  def test_index_should_ignore_project_default_query_if_project_default_query_is_not_public
8508
    query = IssueQuery.find(1)
8509
    query.project.update(default_issue_query: query)
8510

  
8511
    query.update(visibility: Query::VISIBILITY_PRIVATE, user_id: 2)
8512
    query.save!
8513

  
8514
    [User.find(1), User.find(2)].each do |user|
8515
      @request.session[:user_id] = user.id
8516
      @request.session[:issue_query] = nil
8517
      get :index, params: { project_id: query.project.id }
8518
      assert_select 'h2', text: 'Issues'
8519
    end
8520
  end
8521

  
8522
  def test_index_should_ignore_global_default_query_if_global_default_query_is_not_public
8523
    query = IssueQuery.find(1)
8524
    with_settings default_issue_query: query.id do
8525
      query.update(visibility: Query::VISIBILITY_PRIVATE, user_id: 2)
8526
      query.save!
8527

  
8528
      [User.find(1), User.find(2)].each do |user|
8529
        @request.session[:user_id] = user.id
8530
        @request.session[:issue_query] = nil
8531
        get :index
8532
        assert_select 'h2', text: 'Issues'
8533
      end
8534
    end
8535
  end
8485 8536
end
test/functional/projects_controller_test.rb
274 274
    end
275 275
  end
276 276

  
277
  def test_index_should_only_use_user_default_query_for_users_who_have_default_query_available
278
    query = ProjectQuery.find(11)
279

  
280
    query.update(visibility: Query::VISIBILITY_PRIVATE, user_id: 2)
281
    query.save!
282

  
283
    # If visible default query
284
    @request.session[:user_id] = 2
285
    User.find(2).pref.update(default_project_query: query.id)
286
    get :index
287
    assert_select 'h2', text: query.name
288

  
289
    # If invisible default query
290
    @request.session[:user_id] = 3
291
    User.find(3).pref.update(default_project_query: query.id)
292
    get :index
293
    assert_select 'h2', text: I18n.t(:label_project_plural)
294
  end
295

  
296
  def test_index_should_ignore_global_default_query_if_global_default_query_is_not_public
297
    query = ProjectQuery.find(11)
298
    with_settings default_project_query: query.id do
299
      query.update(visibility: Query::VISIBILITY_PRIVATE, user_id: 2)
300
      query.save!
301

  
302
      [User.find(1), User.find(2)].each do |user|
303
        @request.session[:user_id] = user.id
304
        get :index
305
        assert_select 'h2', text: I18n.t(:label_project_plural)
306
      end
307
    end
308
  end
309

  
277 310
  def test_autocomplete_js
278 311
    get(
279 312
      :autocomplete,
test/unit/project_query_test.rb
87 87
    user = User.find(1)
88 88
    query = ProjectQuery.find(11)
89 89
    user_query = ProjectQuery.find(12)
90
    user_query.update(visibility: Query::VISIBILITY_PUBLIC)
90 91

  
91 92
    [nil, user, User.anonymous].each do |u|
92 93
      assert_nil IssueQuery.default(user: u)
test/unit/query_test.rb
2814 2814
    project_query = IssueQuery.find(1)
2815 2815
    query = IssueQuery.find(4)
2816 2816
    user_query = IssueQuery.find(3)
2817
    user_query.update(visibility: Query::VISIBILITY_PUBLIC)
2817 2818
    user_query.update_column :user_id, user.id
2818 2819

  
2819 2820
    [nil, user, User.anonymous].each do |u|