0001-rest-api-filter-issues-by-multiple-tracker-ids.patch

Ko Nagase, 2022-05-27 16:06

Download (2.77 KB)

View differences:

app/models/issue_query.rb
709 709
    end
710 710
  end
711 711

  
712
  def sql_for_tracker_id_field(field, operator, value)
713
    if operator == "="
714
      # accepts a comma separated list of ids
715
      ids = value.join(",").scan(/\d+/).map(&:to_i)
716
      if ids.present?
717
        "tracker_id IN (#{ids.join(",")})"
718
      else
719
        "1=0"
720
      end
721
    else
722
      sql_for_field("tracker_id", operator, value, Issue.table_name, "tracker_id")
723
    end
724
  end
725

  
712 726
  def sql_for_relations(field, operator, value, options={})
713 727
    relation_options = IssueRelation::TYPES[field]
714 728
    return relation_options unless relation_options
test/functional/issues_controller_test.rb
227 227
      },
228 228
      'tracker_id' => {
229 229
        '3' => {:op => '=', :values => ['3']},
230
        '=3' => {:op => '=', :values => ['3']}
230
        '=3' => {:op => '=', :values => ['3']},
231
        '=1,2,3' => {:op => '=', :values => ['1,2,3']}
231 232
      },
232 233
      'start_date' => {
233 234
        '2011-10-12' => {:op => '=', :values => ['2011-10-12']},
test/unit/query_test.rb
769 769
                 query.statement
770 770
  end
771 771

  
772
  def test_filter_on_tracker_id
773
    query = IssueQuery.new(:name => '_')
774

  
775
    query.filters = {'tracker_id' => {:operator => '=', :values => ['1']}}
776
    assert_equal 13, find_issues_with_query(query).size
777

  
778
    query.filters = {'tracker_id' => {:operator => '=', :values => ['2']}}
779
    assert_equal 1, find_issues_with_query(query).size
780

  
781
    query.filters = {'tracker_id' => {:operator => '=', :values => ['3']}}
782
    assert_equal 0, find_issues_with_query(query).size
783

  
784
    query.filters = {'tracker_id' => {:operator => '=', :values => ['1,2,3']}}
785
    assert_equal 14, find_issues_with_query(query).size
786
  end
787

  
772 788
  def test_filter_assigned_to_me
773 789
    user = User.find(2)
774 790
    group = Group.find(10)
775
-