mirror of
https://github.com/meineerde/redmine.git
synced 2026-02-01 03:57:15 +00:00
Extend "contains" operator in "Parent task" filter to support multiple issue IDs (#39805).
Patch by Go MAEDA (@maeda). git-svn-id: https://svn.redmine.org/redmine/trunk@22577 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
f02e2c088b
commit
13028b913b
@ -662,9 +662,18 @@ class IssueQuery < Query
|
||||
"1=0"
|
||||
end
|
||||
when "~"
|
||||
root_id, lft, rgt = Issue.where(:id => value.first.to_i).pick(:root_id, :lft, :rgt)
|
||||
if root_id && lft && rgt
|
||||
"#{Issue.table_name}.root_id = #{root_id} AND #{Issue.table_name}.lft > #{lft} AND #{Issue.table_name}.rgt < #{rgt}"
|
||||
ids = value.first.to_s.scan(/\d+/).map(&:to_i).uniq
|
||||
conditions = ids.filter_map do |id|
|
||||
root_id, lft, rgt = Issue.where(id: id).pick(:root_id, :lft, :rgt)
|
||||
if root_id && lft && rgt
|
||||
"(#{Issue.table_name}.root_id = #{root_id} AND #{Issue.table_name}.lft > #{lft} AND #{Issue.table_name}.rgt < #{rgt})"
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
if conditions.any?
|
||||
"(#{conditions.join(' OR ')})"
|
||||
else
|
||||
"1=0"
|
||||
end
|
||||
|
||||
@ -1819,6 +1819,31 @@ class QueryTest < ActiveSupport::TestCase
|
||||
assert_equal [], find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_operator_contains_on_parent_id_should_accept_comma_separated_values
|
||||
parent1 = Issue.generate!
|
||||
children_of_parent1 = [
|
||||
Issue.generate!(parent_id: parent1.id),
|
||||
Issue.generate!(parent_id: parent1.id)
|
||||
]
|
||||
parent2 = Issue.generate!
|
||||
children_of_parent2 = [
|
||||
Issue.generate!(parent_id: parent2.id),
|
||||
Issue.generate!(parent_id: parent2.id)
|
||||
]
|
||||
grandchild_of_parent2 = [
|
||||
Issue.generate!(parent_id: children_of_parent2.first.id)
|
||||
]
|
||||
|
||||
query = IssueQuery.new(name: '_')
|
||||
query.add_filter('parent_id', '~', ["#{parent1.id},#{parent2.id}"])
|
||||
issues = find_issues_with_query(query)
|
||||
|
||||
expected =
|
||||
children_of_parent1 + children_of_parent2 + grandchild_of_parent2
|
||||
assert_equal expected.size, issues.size
|
||||
assert_equal expected.map(&:id).sort, issues.map(&:id).sort
|
||||
end
|
||||
|
||||
def test_filter_on_child
|
||||
Issue.delete_all
|
||||
parent = Issue.generate_with_descendants!
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user