Project

General

Profile

Feature #38402 » fix-any_searchable-does-not-support-mine-and-bookmarks.patch

Go MAEDA, 2023-04-18 11:08

View differences:

app/models/issue_query.rb
784 784
    if project
785 785
      projects = project_scope.where(project_statement)
786 786
    elsif has_filter?('project_id')
787
      case values_for('project_id').first
788
      when 'mine'
789
        project_ids = User.current.projects.ids
790
      when 'bookmarks'
791
        project_ids = User.current.bookmarked_project_ids
792
      else
793
        project_ids = values_for('project_id')
794
      end
787 795
      projects = project_scope.where(
788
        sql_for_field('project_id', operator_for('project_id'), values_for('project_id'), Project.table_name, 'id')
796
        sql_for_field('project_id', operator_for('project_id'), project_ids, Project.table_name, 'id')
789 797
      )
790 798
    else
791 799
      projects = nil
test/unit/query_test.rb
1041 1041
    assert_equal [1, 3], result.map(&:id).sort
1042 1042
  end
1043 1043

  
1044
  def test_filter_any_searchable_with_my_projects
1045
    # This user's project is ecookbook only
1046
    User.current = User.find_by(login: 'dlopper')
1047
    query = IssueQuery.new(
1048
      :name => '_',
1049
      :filters => {
1050
        'any_searchable' => {:operator => '~', :values => ['issue']},
1051
        'project_id' => {:operator => '=', :values => ['mine']}
1052
      }
1053
    )
1054
    result = find_issues_with_query(query)
1055
    assert_equal [7, 8, 11, 12], result.map(&:id).sort
1056
    result.each {|issue| assert_equal 1, issue.project_id}
1057
  end
1058

  
1059
  def test_filter_any_searchable_with_my_bookmarks
1060
    # This user bookmarks two projects, ecookbook and private-child
1061
    User.current = User.find(1)
1062
    query = IssueQuery.new(
1063
      :name => '_',
1064
      :filters => {
1065
        'any_searchable' => {:operator => '~', :values => ['issue']},
1066
        'project_id' => {:operator => '=', :values => ['bookmarks']}
1067
      }
1068
    )
1069
    result = find_issues_with_query(query)
1070
    assert_equal [6, 7, 8, 9, 10, 11, 12], result.map(&:id).sort
1071
    result.each {|issue| assert_includes [1, 5], issue.project_id}
1072
  end
1073

  
1044 1074
  def test_filter_updated_by
1045 1075
    user = User.generate!
1046 1076
    Journal.create!(:user_id => user.id, :journalized => Issue.find(2), :notes => 'Notes')
(8-8/8)