is_not_filter_for_subprojects.diff

Marius BALTEANU, 2016-12-26 10:27

Download (3.83 KB)

View differences:

app/models/query.rb
235 235
    :list => [ "=", "!" ],
236 236
    :list_status => [ "o", "=", "!", "c", "*" ],
237 237
    :list_optional => [ "=", "!", "!*", "*" ],
238
    :list_subprojects => [ "*", "!*", "=" ],
238
    :list_subprojects => [ "*", "!*", "=", "!" ],
239 239
    :date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
240 240
    :date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "!*", "*" ],
241 241
    :string => [ "=", "~", "!", "!~", "!*", "*" ],
......
661 661

  
662 662
  def project_statement
663 663
    project_clauses = []
664
    if project && !project.descendants.active.empty?
664
    active_subprojects_ids = []
665

  
666
    active_subprojects_ids = project.descendants.active.map(&:id) if project
667
    if active_subprojects_ids.any?
665 668
      if has_filter?("subproject_id")
666 669
        case operator_for("subproject_id")
667 670
        when '='
668 671
          # include the selected subprojects
669
          ids = [project.id] + values_for("subproject_id").each(&:to_i)
672
          ids = [project.id] + values_for("subproject_id").map(&:to_i)
673
          project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
674
        when '!'
675
          # exclude the selected subprojects
676
          ids = [project.id] + active_subprojects_ids - values_for("subproject_id").map(&:to_i)
670 677
          project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
671 678
        when '!*'
672 679
          # main project only
test/unit/query_test.rb
682 682
    Member.create!(:project_id => 1, :principal => other_group, :role_ids => [1])
683 683
    User.current = user
684 684

  
685
    with_settings :issue_group_assignment => '1' do 
685
    with_settings :issue_group_assignment => '1' do
686 686
      i1 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => user)
687 687
      i2 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => group)
688 688
      i3 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => other_group)
689
  
689

  
690 690
      query = IssueQuery.new(:name => '_', :filters => { 'assigned_to_id' => {:operator => '=', :values => ['me']}})
691 691
      result = query.issues
692 692
      assert_equal Issue.visible.where(:assigned_to_id => ([2] + user.reload.group_ids)).sort_by(&:id), result.sort_by(&:id)
693
  
693

  
694 694
      assert result.include?(i1)
695 695
      assert result.include?(i2)
696 696
      assert !result.include?(i3)
......
1810 1810
    ActiveRecord::Base.default_timezone = :local # restore Redmine default
1811 1811
  end
1812 1812

  
1813
  def test_filter_on_subprojects
1814
    query = IssueQuery.new(:name => '_', :project => Project.find(1))
1815
    filter_name = "subproject_id"
1816
    assert_include filter_name, query.available_filters.keys
1817

  
1818
    # "is" operator should include issues of parent project + issues of the selected subproject
1819
    query.filters = {filter_name => {:operator => '=', :values => ['3']}}
1820
    issues = find_issues_with_query(query)
1821
    assert_equal [1, 2, 3, 5, 7, 8, 11, 12, 13, 14], issues.map(&:id).sort
1822

  
1823
    # "is not" operator should include issues of parent project + issues of all active subprojects - issues of the selected subprojects
1824
    query = IssueQuery.new(:name => '_', :project => Project.find(1))
1825
    query.filters = {filter_name => {:operator => '!', :values => ['3']}}
1826
    issues = find_issues_with_query(query)
1827
    assert_equal [1, 2, 3, 6, 7, 8, 9, 10, 11, 12], issues.map(&:id).sort
1828
  end
1829

  
1813 1830
end