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
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
......
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