summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2019-02-27 17:51:20 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2019-03-04 17:44:57 +0100
commit712148518bc36ad68251f0eef129c13461c82192 (patch)
tree18198f3db337d0cf30964538a83eaec42f9822aa /lib/api
parent6c9e26a2a0abcf5a7fdff027688e0c5204afed9e (diff)
downloadgitlab-ce-712148518bc36ad68251f0eef129c13461c82192.tar.gz
Refactor API::Search for EE
This refactors API::Search so that Enterprise Edition can more easily extend its functionality, without having to modify the file directly.
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/helpers/search_helpers.rb22
-rw-r--r--lib/api/search.rb25
2 files changed, 38 insertions, 9 deletions
diff --git a/lib/api/helpers/search_helpers.rb b/lib/api/helpers/search_helpers.rb
new file mode 100644
index 00000000000..47fb5a36327
--- /dev/null
+++ b/lib/api/helpers/search_helpers.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module API
+ module Helpers
+ module SearchHelpers
+ def self.global_search_scopes
+ # This is a separate method so that EE can redefine it.
+ %w(projects issues merge_requests milestones snippet_titles snippet_blobs)
+ end
+
+ def self.group_search_scopes
+ # This is a separate method so that EE can redefine it.
+ %w(projects issues merge_requests milestones)
+ end
+
+ def self.project_search_scopes
+ # This is a separate method so that EE can redefine it.
+ %w(issues merge_requests milestones notes wiki_blobs commits blobs)
+ end
+ end
+ end
+end
diff --git a/lib/api/search.rb b/lib/api/search.rb
index f5db692afe5..f65e810bf90 100644
--- a/lib/api/search.rb
+++ b/lib/api/search.rb
@@ -45,6 +45,12 @@ module API
def entity
SCOPE_ENTITY[params[:scope].to_sym]
end
+
+ def verify_search_scope!
+ # In EE we have additional validation requirements for searches.
+ # Defining this method here as a noop allows us to easily extend it in
+ # EE, without having to modify this file directly.
+ end
end
resource :search do
@@ -55,12 +61,13 @@ module API
requires :search, type: String, desc: 'The expression it should be searched for'
requires :scope,
type: String,
- desc: 'The scope of search, available scopes:
- projects, issues, merge_requests, milestones, snippet_titles, snippet_blobs',
- values: %w(projects issues merge_requests milestones snippet_titles snippet_blobs)
+ desc: 'The scope of the search',
+ values: Helpers::SearchHelpers.global_search_scopes
use :pagination
end
get do
+ verify_search_scope!
+
present search, with: entity
end
end
@@ -74,12 +81,13 @@ module API
requires :search, type: String, desc: 'The expression it should be searched for'
requires :scope,
type: String,
- desc: 'The scope of search, available scopes:
- projects, issues, merge_requests, milestones',
- values: %w(projects issues merge_requests milestones)
+ desc: 'The scope of the search',
+ values: Helpers::SearchHelpers.group_search_scopes
use :pagination
end
get ':id/(-/)search' do
+ verify_search_scope!
+
present search(group_id: user_group.id), with: entity
end
end
@@ -93,9 +101,8 @@ module API
requires :search, type: String, desc: 'The expression it should be searched for'
requires :scope,
type: String,
- desc: 'The scope of search, available scopes:
- issues, merge_requests, milestones, notes, wiki_blobs, commits, blobs',
- values: %w(issues merge_requests milestones notes wiki_blobs commits blobs)
+ desc: 'The scope of the search',
+ values: Helpers::SearchHelpers.project_search_scopes
use :pagination
end
get ':id/(-/)search' do