Commit b43cb21d authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '26379-iid-param' into 'master'

add a :iid param to the IssuableFinder

Closes #26379

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