Allow searching by namespace name, include public projects
GITLAB-1457 (GITLAB-836) Change-Id: If8e2474bc6908accca51f395f58937687f101b58
This commit is contained in:
parent
cddec75dc1
commit
0f87ae3be5
|
@ -9,11 +9,14 @@ class SearchContext
|
|||
query = params[:search]
|
||||
|
||||
return result unless query.present?
|
||||
|
||||
projects = Project.where(id: project_ids)
|
||||
result[:projects] = projects.search(query).limit(20)
|
||||
result[:projects] = Project.where("projects.id in (?) OR projects.public = true", project_ids).search(query).limit(20)
|
||||
|
||||
# Search inside single project
|
||||
single_project_search(Project.where(id: project_ids), query)
|
||||
result
|
||||
end
|
||||
|
||||
def single_project_search(projects, query)
|
||||
project = projects.first if projects.length == 1
|
||||
|
||||
if params[:search_code].present?
|
||||
|
@ -23,7 +26,6 @@ class SearchContext
|
|||
result[:issues] = Issue.where(project_id: project_ids).search(query).order('updated_at DESC').limit(20)
|
||||
result[:wiki_pages] = []
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def result
|
||||
|
|
|
@ -122,7 +122,7 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def search query
|
||||
where("projects.name LIKE :query OR projects.path LIKE :query", query: "%#{query}%")
|
||||
joins(:namespace).where("projects.name LIKE :query OR projects.path LIKE :query OR namespaces.name LIKE :query", query: "%#{query}%")
|
||||
end
|
||||
|
||||
def find_with_namespace(id)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe SearchContext do
|
||||
let(:found_namespace) { create(:namespace, name: 'searchable namespace', path:'another_thing') }
|
||||
let(:user) { create(:user, namespace: found_namespace) }
|
||||
let!(:found_project) { create(:project, name: 'searchable_project', creator_id: user.id, namespace: found_namespace, public: false) }
|
||||
|
||||
let(:unfound_namespace) { create(:namespace, name: 'unfound namespace', path: 'yet_something_else') }
|
||||
let!(:unfound_project) { create(:project, name: 'unfound_project', creator_id: user.id, namespace: unfound_namespace, public: false) }
|
||||
let(:public_namespace) { create(:namespace, path: 'something_else',name: 'searchable public namespace') }
|
||||
let(:other_user) { create(:user, namespace: public_namespace) }
|
||||
let!(:public_project) { create(:project, name: 'searchable_public_project', creator_id: other_user.id, namespace: public_namespace, public: true) }
|
||||
|
||||
describe '#execute' do
|
||||
it 'public projects should be searchable' do
|
||||
context = SearchContext.new([found_project.id], {search_code: false, search: "searchable"})
|
||||
results = context.execute
|
||||
results[:projects].should == [found_project, public_project]
|
||||
end
|
||||
|
||||
it 'namespace name should be searchable' do
|
||||
context = SearchContext.new([found_project.id], {search_code: false, search: "searchable namespace"})
|
||||
results = context.execute
|
||||
results[:projects].should == [found_project]
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue