GitLab wurde aktualisiert. Dank regelmäßiger Updates bleibt das THM GitLab sicher und Sie profitieren von den neuesten Funktionen. Vielen Dank für Ihre Geduld.

Commit 9349a71e authored by jplang's avatar jplang
Browse files

Filtering out specific subprojects (using 'is not' operator) (#15773).

Patch by Marius BALTEANU.

git-svn-id: https://svn.redmine.org/redmine/trunk@16196 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent bf5fdb19
...@@ -269,7 +269,7 @@ class Query < ActiveRecord::Base ...@@ -269,7 +269,7 @@ class Query < ActiveRecord::Base
:list => [ "=", "!" ], :list => [ "=", "!" ],
:list_status => [ "o", "=", "!", "c", "*" ], :list_status => [ "o", "=", "!", "c", "*" ],
:list_optional => [ "=", "!", "!*", "*" ], :list_optional => [ "=", "!", "!*", "*" ],
:list_subprojects => [ "*", "!*", "=" ], :list_subprojects => [ "*", "!*", "=", "!" ],
:date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ], :date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
:date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "!*", "*" ], :date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "!*", "*" ],
:string => [ "=", "~", "!", "!~", "!*", "*" ], :string => [ "=", "~", "!", "!~", "!*", "*" ],
...@@ -756,12 +756,19 @@ class Query < ActiveRecord::Base ...@@ -756,12 +756,19 @@ class Query < ActiveRecord::Base
def project_statement def project_statement
project_clauses = [] project_clauses = []
if project && !project.descendants.active.empty? active_subprojects_ids = []
active_subprojects_ids = project.descendants.active.map(&:id) if project
if active_subprojects_ids.any?
if has_filter?("subproject_id") if has_filter?("subproject_id")
case operator_for("subproject_id") case operator_for("subproject_id")
when '=' when '='
# include the selected subprojects # include the selected subprojects
ids = [project.id] + values_for("subproject_id").each(&:to_i) ids = [project.id] + values_for("subproject_id").map(&:to_i)
project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
when '!'
# exclude the selected subprojects
ids = [project.id] + active_subprojects_ids - values_for("subproject_id").map(&:to_i)
project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',')
when '!*' when '!*'
# main project only # main project only
......
...@@ -704,15 +704,15 @@ class QueryTest < ActiveSupport::TestCase ...@@ -704,15 +704,15 @@ class QueryTest < ActiveSupport::TestCase
Member.create!(:project_id => 1, :principal => other_group, :role_ids => [1]) Member.create!(:project_id => 1, :principal => other_group, :role_ids => [1])
User.current = user User.current = user
with_settings :issue_group_assignment => '1' do with_settings :issue_group_assignment => '1' do
i1 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => user) i1 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => user)
i2 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => group) i2 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => group)
i3 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => other_group) i3 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => other_group)
query = IssueQuery.new(:name => '_', :filters => { 'assigned_to_id' => {:operator => '=', :values => ['me']}}) query = IssueQuery.new(:name => '_', :filters => { 'assigned_to_id' => {:operator => '=', :values => ['me']}})
result = query.issues result = query.issues
assert_equal Issue.visible.where(:assigned_to_id => ([2] + user.reload.group_ids)).sort_by(&:id), result.sort_by(&:id) assert_equal Issue.visible.where(:assigned_to_id => ([2] + user.reload.group_ids)).sort_by(&:id), result.sort_by(&:id)
assert result.include?(i1) assert result.include?(i1)
assert result.include?(i2) assert result.include?(i2)
assert !result.include?(i3) assert !result.include?(i3)
...@@ -1875,4 +1875,21 @@ class QueryTest < ActiveSupport::TestCase ...@@ -1875,4 +1875,21 @@ class QueryTest < ActiveSupport::TestCase
ActiveRecord::Base.default_timezone = :local # restore Redmine default ActiveRecord::Base.default_timezone = :local # restore Redmine default
end end
def test_filter_on_subprojects
query = IssueQuery.new(:name => '_', :project => Project.find(1))
filter_name = "subproject_id"
assert_include filter_name, query.available_filters.keys
# "is" operator should include issues of parent project + issues of the selected subproject
query.filters = {filter_name => {:operator => '=', :values => ['3']}}
issues = find_issues_with_query(query)
assert_equal [1, 2, 3, 5, 7, 8, 11, 12, 13, 14], issues.map(&:id).sort
# "is not" operator should include issues of parent project + issues of all active subprojects - issues of the selected subprojects
query = IssueQuery.new(:name => '_', :project => Project.find(1))
query.filters = {filter_name => {:operator => '!', :values => ['3']}}
issues = find_issues_with_query(query)
assert_equal [1, 2, 3, 6, 7, 8, 9, 10, 11, 12], issues.map(&:id).sort
end
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment