Commit 7362fd6f authored by mhasbini's avatar mhasbini

add a :iids param to IssuableFinder

parent 827a56a4
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
# label_name: string # label_name: string
# sort: string # sort: string
# non_archived: boolean # non_archived: boolean
# iids: integer[]
# #
class IssuableFinder class IssuableFinder
NONE = '0' NONE = '0'
...@@ -40,6 +41,7 @@ class IssuableFinder ...@@ -40,6 +41,7 @@ class IssuableFinder
items = by_label(items) items = by_label(items)
items = by_due_date(items) items = by_due_date(items)
items = by_non_archived(items) items = by_non_archived(items)
items = by_iids(items)
sort(items) sort(items)
end end
...@@ -266,16 +268,11 @@ class IssuableFinder ...@@ -266,16 +268,11 @@ class IssuableFinder
end end
def by_search(items) def by_search(items)
if search search ? items.full_search(search) : items
items = end
if search =~ iid_pattern
items.where(iid: $~[:iid])
else
items.full_search(search)
end
end
items def by_iids(items)
params[:iids].present? ? items.where(iid: params[:iids]) : items
end end
def sort(items) def sort(items)
......
...@@ -26,10 +26,6 @@ class IssuesFinder < IssuableFinder ...@@ -26,10 +26,6 @@ class IssuesFinder < IssuableFinder
IssuesFinder.not_restricted_by_confidentiality(current_user) IssuesFinder.not_restricted_by_confidentiality(current_user)
end end
def iid_pattern
@iid_pattern ||= %r{\A#{Regexp.escape(Issue.reference_prefix)}(?<iid>\d+)\z}
end
def self.not_restricted_by_confidentiality(user) def self.not_restricted_by_confidentiality(user)
return Issue.where('issues.confidential IS NULL OR issues.confidential IS FALSE') if user.blank? return Issue.where('issues.confidential IS NULL OR issues.confidential IS FALSE') if user.blank?
......
...@@ -20,14 +20,4 @@ class MergeRequestsFinder < IssuableFinder ...@@ -20,14 +20,4 @@ class MergeRequestsFinder < IssuableFinder
def klass def klass
MergeRequest MergeRequest
end end
private
def iid_pattern
@iid_pattern ||= %r{\A[
#{Regexp.escape(MergeRequest.reference_prefix)}
#{Regexp.escape(Issue.reference_prefix)}
](?<iid>\d+)\z
}x
end
end end
---
title: add :iids param to IssuableFinder (resolve technical dept)
merge_request: 9222
author: mhasbini
...@@ -16,7 +16,8 @@ module API ...@@ -16,7 +16,8 @@ module API
labels = args.delete(:labels) labels = args.delete(:labels)
args[:label_name] = labels if match_all_labels args[:label_name] = labels if match_all_labels
args[:search] = "#{Issue.reference_prefix}#{args.delete(:iid)}" if args.key?(:iid) # IssuesFinder expects iids
args[:iids] = args.delete(:iid) if args.key?(:iid)
issues = IssuesFinder.new(current_user, args).execute.inc_notes_with_associations issues = IssuesFinder.new(current_user, args).execute.inc_notes_with_associations
......
...@@ -136,10 +136,10 @@ describe IssuesFinder do ...@@ -136,10 +136,10 @@ describe IssuesFinder do
end end
end end
context 'filtering by issue iid' do context 'filtering by issues iids' do
let(:params) { { search: issue3.to_reference } } let(:params) { { iids: issue3.iid } }
it 'returns issue with iid match' do it 'returns issues with iids match' do
expect(issues).to contain_exactly(issue3) expect(issues).to contain_exactly(issue3)
end end
end end
......
...@@ -38,5 +38,13 @@ describe MergeRequestsFinder do ...@@ -38,5 +38,13 @@ describe MergeRequestsFinder do
merge_requests = MergeRequestsFinder.new(user, params).execute merge_requests = MergeRequestsFinder.new(user, params).execute
expect(merge_requests.size).to eq(3) expect(merge_requests.size).to eq(3)
end end
it 'filters by iid' do
params = { project_id: project1.id, iids: merge_request1.iid }
merge_requests = MergeRequestsFinder.new(user, params).execute
expect(merge_requests).to contain_exactly(merge_request1)
end
end 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