Commit 71214851 authored by Yorick Peterse's avatar Yorick Peterse

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.
parent 6c9e26a2
# 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
...@@ -45,6 +45,12 @@ module API ...@@ -45,6 +45,12 @@ module API
def entity def entity
SCOPE_ENTITY[params[:scope].to_sym] SCOPE_ENTITY[params[:scope].to_sym]
end 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 end
resource :search do resource :search do
...@@ -55,12 +61,13 @@ module API ...@@ -55,12 +61,13 @@ module API
requires :search, type: String, desc: 'The expression it should be searched for' requires :search, type: String, desc: 'The expression it should be searched for'
requires :scope, requires :scope,
type: String, type: String,
desc: 'The scope of search, available scopes: desc: 'The scope of the search',
projects, issues, merge_requests, milestones, snippet_titles, snippet_blobs', values: Helpers::SearchHelpers.global_search_scopes
values: %w(projects issues merge_requests milestones snippet_titles snippet_blobs)
use :pagination use :pagination
end end
get do get do
verify_search_scope!
present search, with: entity present search, with: entity
end end
end end
...@@ -74,12 +81,13 @@ module API ...@@ -74,12 +81,13 @@ module API
requires :search, type: String, desc: 'The expression it should be searched for' requires :search, type: String, desc: 'The expression it should be searched for'
requires :scope, requires :scope,
type: String, type: String,
desc: 'The scope of search, available scopes: desc: 'The scope of the search',
projects, issues, merge_requests, milestones', values: Helpers::SearchHelpers.group_search_scopes
values: %w(projects issues merge_requests milestones)
use :pagination use :pagination
end end
get ':id/(-/)search' do get ':id/(-/)search' do
verify_search_scope!
present search(group_id: user_group.id), with: entity present search(group_id: user_group.id), with: entity
end end
end end
...@@ -93,9 +101,8 @@ module API ...@@ -93,9 +101,8 @@ module API
requires :search, type: String, desc: 'The expression it should be searched for' requires :search, type: String, desc: 'The expression it should be searched for'
requires :scope, requires :scope,
type: String, type: String,
desc: 'The scope of search, available scopes: desc: 'The scope of the search',
issues, merge_requests, milestones, notes, wiki_blobs, commits, blobs', values: Helpers::SearchHelpers.project_search_scopes
values: %w(issues merge_requests milestones notes wiki_blobs commits blobs)
use :pagination use :pagination
end end
get ':id/(-/)search' do get ':id/(-/)search' do
......
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