Refactor: replace chained finders with an inject. Should handle edge cases better.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4079 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
41f8d043eb
commit
d36700eeee
|
@ -441,16 +441,21 @@ class Query < ActiveRecord::Base
|
||||||
elsif field == "member_of_group" # named field
|
elsif field == "member_of_group" # named field
|
||||||
if operator == '*' # Any group
|
if operator == '*' # Any group
|
||||||
groups = Group.all
|
groups = Group.all
|
||||||
members_of_groups = groups.collect(&:user_ids).flatten.compact.collect(&:to_s)
|
|
||||||
operator = '=' # Override the operator since we want to find by assigned_to
|
operator = '=' # Override the operator since we want to find by assigned_to
|
||||||
elsif operator == "!*"
|
elsif operator == "!*"
|
||||||
groups = Group.all
|
groups = Group.all
|
||||||
members_of_groups = groups.collect(&:user_ids).flatten.compact.collect(&:to_s)
|
|
||||||
operator = '!' # Override the operator since we want to find by assigned_to
|
operator = '!' # Override the operator since we want to find by assigned_to
|
||||||
else
|
else
|
||||||
groups = Group.find_all_by_id(v)
|
groups = Group.find_all_by_id(v)
|
||||||
members_of_groups = groups.collect(&:user_ids).flatten.compact.collect(&:to_s)
|
|
||||||
end
|
end
|
||||||
|
groups ||= []
|
||||||
|
|
||||||
|
members_of_groups = groups.inject([]) {|user_ids, group|
|
||||||
|
if group && group.user_ids.present?
|
||||||
|
user_ids << group.user_ids
|
||||||
|
end
|
||||||
|
user_ids.flatten.uniq.compact
|
||||||
|
}.sort.collect(&:to_s)
|
||||||
|
|
||||||
sql << '(' + sql_for_field("assigned_to_id", operator, members_of_groups, Issue.table_name, "assigned_to_id", false) + ')'
|
sql << '(' + sql_for_field("assigned_to_id", operator, members_of_groups, Issue.table_name, "assigned_to_id", false) + ')'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue