##// END OF EJS Templates
Filtering out specific subprojects (using 'is not' operator) (#15773)....
Jean-Philippe Lang -
r15814:e808c6225323
parent child
Show More
@@ -269,7 +269,7 class Query < ActiveRecord::Base
269 :list => [ "=", "!" ],
269 :list => [ "=", "!" ],
270 :list_status => [ "o", "=", "!", "c", "*" ],
270 :list_status => [ "o", "=", "!", "c", "*" ],
271 :list_optional => [ "=", "!", "!*", "*" ],
271 :list_optional => [ "=", "!", "!*", "*" ],
272 :list_subprojects => [ "*", "!*", "=" ],
272 :list_subprojects => [ "*", "!*", "=", "!" ],
273 :date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
273 :date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
274 :date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "!*", "*" ],
274 :date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "!*", "*" ],
275 :string => [ "=", "~", "!", "!~", "!*", "*" ],
275 :string => [ "=", "~", "!", "!~", "!*", "*" ],
@@ -756,12 +756,19 class Query < ActiveRecord::Base
756
756
757 def project_statement
757 def project_statement
758 project_clauses = []
758 project_clauses = []
759 if project && !project.descendants.active.empty?
759 active_subprojects_ids = []
760
761 active_subprojects_ids = project.descendants.active.map(&:id) if project
762 if active_subprojects_ids.any?
760 if has_filter?("subproject_id")
763 if has_filter?("subproject_id")
761 case operator_for("subproject_id")
764 case operator_for("subproject_id")
762 when '='
765 when '='
763 # include the selected subprojects
766 # include the selected subprojects
764 ids = [project.id] + values_for("subproject_id").each(&:to_i)
767 ids = [project.id] + values_for("subproject_id").map(&:to_i)
768 project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
769 when '!'
770 # exclude the selected subprojects
771 ids = [project.id] + active_subprojects_ids - values_for("subproject_id").map(&:to_i)
765 project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
772 project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
766 when '!*'
773 when '!*'
767 # main project only
774 # main project only
@@ -704,15 +704,15 class QueryTest < ActiveSupport::TestCase
704 Member.create!(:project_id => 1, :principal => other_group, :role_ids => [1])
704 Member.create!(:project_id => 1, :principal => other_group, :role_ids => [1])
705 User.current = user
705 User.current = user
706
706
707 with_settings :issue_group_assignment => '1' do
707 with_settings :issue_group_assignment => '1' do
708 i1 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => user)
708 i1 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => user)
709 i2 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => group)
709 i2 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => group)
710 i3 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => other_group)
710 i3 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => other_group)
711
711
712 query = IssueQuery.new(:name => '_', :filters => { 'assigned_to_id' => {:operator => '=', :values => ['me']}})
712 query = IssueQuery.new(:name => '_', :filters => { 'assigned_to_id' => {:operator => '=', :values => ['me']}})
713 result = query.issues
713 result = query.issues
714 assert_equal Issue.visible.where(:assigned_to_id => ([2] + user.reload.group_ids)).sort_by(&:id), result.sort_by(&:id)
714 assert_equal Issue.visible.where(:assigned_to_id => ([2] + user.reload.group_ids)).sort_by(&:id), result.sort_by(&:id)
715
715
716 assert result.include?(i1)
716 assert result.include?(i1)
717 assert result.include?(i2)
717 assert result.include?(i2)
718 assert !result.include?(i3)
718 assert !result.include?(i3)
@@ -1875,4 +1875,21 class QueryTest < ActiveSupport::TestCase
1875 ActiveRecord::Base.default_timezone = :local # restore Redmine default
1875 ActiveRecord::Base.default_timezone = :local # restore Redmine default
1876 end
1876 end
1877
1877
1878 def test_filter_on_subprojects
1879 query = IssueQuery.new(:name => '_', :project => Project.find(1))
1880 filter_name = "subproject_id"
1881 assert_include filter_name, query.available_filters.keys
1882
1883 # "is" operator should include issues of parent project + issues of the selected subproject
1884 query.filters = {filter_name => {:operator => '=', :values => ['3']}}
1885 issues = find_issues_with_query(query)
1886 assert_equal [1, 2, 3, 5, 7, 8, 11, 12, 13, 14], issues.map(&:id).sort
1887
1888 # "is not" operator should include issues of parent project + issues of all active subprojects - issues of the selected subprojects
1889 query = IssueQuery.new(:name => '_', :project => Project.find(1))
1890 query.filters = {filter_name => {:operator => '!', :values => ['3']}}
1891 issues = find_issues_with_query(query)
1892 assert_equal [1, 2, 3, 6, 7, 8, 9, 10, 11, 12], issues.map(&:id).sort
1893 end
1894
1878 end
1895 end
General Comments 0
You need to be logged in to leave comments. Login now