Commit 44cff5e8 authored by Valery Sizov's avatar Valery Sizov

Search for issues with multiple assignees

parent a240dbab
...@@ -309,18 +309,6 @@ class IssuableFinder ...@@ -309,18 +309,6 @@ class IssuableFinder
params[:sort] ? items.sort(params[:sort], excluded_labels: label_names) : items.reorder(id: :desc) params[:sort] ? items.sort(params[:sort], excluded_labels: label_names) : items.reorder(id: :desc)
end end
def by_assignee(items)
if assignee
items = items.where(assignee_id: assignee.id)
elsif no_assignee?
items = items.where(assignee_id: nil)
elsif assignee_id? || assignee_username? # assignee not found
items = items.none
end
items
end
def by_author(items) def by_author(items)
if author if author
items = items.where(author_id: author.id) items = items.where(author_id: author.id)
......
...@@ -95,7 +95,13 @@ class IssuesFinder < IssuableFinder ...@@ -95,7 +95,13 @@ class IssuesFinder < IssuableFinder
end end
def by_assignee(items) def by_assignee(items)
if assignee if assignees.any?
assignees.each do |assignee|
items = items.assigned_to(assignee)
end
items
elsif assignee && assignees.empty?
items.assigned_to(assignee) items.assigned_to(assignee)
elsif no_assignee? elsif no_assignee?
items.unassigned items.unassigned
...@@ -106,6 +112,19 @@ class IssuesFinder < IssuableFinder ...@@ -106,6 +112,19 @@ class IssuesFinder < IssuableFinder
end end
end end
def assignees
return @assignees if defined?(@assignees)
@assignees =
if params[:assignee_ids]
User.where(id: params[:assignee_ids])
elsif params[:assignee_usernames]
User.where(username: params[:assignee_usernames])
else
[]
end
end
def item_project_ids(items) def item_project_ids(items)
items&.reorder(nil)&.select(:project_id) items&.reorder(nil)&.select(:project_id)
end end
......
...@@ -24,6 +24,18 @@ class MergeRequestsFinder < IssuableFinder ...@@ -24,6 +24,18 @@ class MergeRequestsFinder < IssuableFinder
private private
def by_assignee(items)
if assignee
items = items.where(assignee_id: assignee.id)
elsif no_assignee?
items = items.where(assignee_id: nil)
elsif assignee_id? || assignee_username? # assignee not found
items = items.none
end
items
end
def item_project_ids(items) def item_project_ids(items)
items&.reorder(nil)&.select(:target_project_id) items&.reorder(nil)&.select(:target_project_id)
end end
......
...@@ -59,6 +59,36 @@ describe IssuesFinder do ...@@ -59,6 +59,36 @@ describe IssuesFinder do
end end
end end
context 'filtering by assignee IDs' do
set(:user3) { create(:user) }
let(:params) { { assignee_ids: [user2.id, user3.id] } }
before do
project2.team << [user3, :developer]
issue3.assignees = [user2, user3]
end
it 'returns issues assigned to those users' do
expect(issues).to contain_exactly(issue3)
end
end
context 'filtering by assignee usernames' do
set(:user3) { create(:user) }
let(:params) { { assignee_usernames: [user2.username, user3.username] } }
before do
project2.team << [user3, :developer]
issue3.assignees = [user2, user3]
end
it 'returns issues assigned to those users' do
expect(issues).to contain_exactly(issue3)
end
end
context 'filtering by author ID' do context 'filtering by author ID' do
let(:params) { { author_id: user2.id } } let(:params) { { author_id: user2.id } }
......
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