Allow public repo searching
GITLAB-1386 Change-Id: I9a0bbe8db1a9bb00cef33b3e1854d78844b70a45
This commit is contained in:
parent
c946defb3d
commit
91c7b266cd
2 changed files with 33 additions and 10 deletions
|
@ -3,16 +3,7 @@ class SearchController < ApplicationController
|
|||
project_id = params[:project_id]
|
||||
group_id = params[:group_id]
|
||||
|
||||
project_ids = current_user.authorized_projects.map(&:id)
|
||||
|
||||
if group_id.present?
|
||||
@group = Group.find(group_id)
|
||||
group_project_ids = @group.projects.map(&:id)
|
||||
project_ids.select! { |id| group_project_ids.include?(id)}
|
||||
elsif project_id.present?
|
||||
@project = Project.find(params[:project_id])
|
||||
project_ids.select! { |id| id == project_id.to_i}
|
||||
end
|
||||
project_ids = find_project_ids(group_id, project_id)
|
||||
|
||||
result = SearchContext.new(project_ids, params).execute
|
||||
|
||||
|
@ -23,4 +14,18 @@ class SearchController < ApplicationController
|
|||
@blobs = Kaminari.paginate_array(result[:blobs]).page(params[:page]).per(20)
|
||||
@total_results = @projects.count + @merge_requests.count + @issues.count + @wiki_pages.count + @blobs.total_count
|
||||
end
|
||||
|
||||
def find_project_ids(group_id, project_id)
|
||||
project_ids = current_user.authorized_projects.map(&:id)
|
||||
|
||||
if group_id.present?
|
||||
@group = Group.find(group_id)
|
||||
group_project_ids = @group.projects.map(&:id)
|
||||
project_ids.select! { |id| group_project_ids.include?(id) }
|
||||
elsif project_id.present?
|
||||
@project = Project.find(project_id)
|
||||
project_ids = @project.public ? [@project.id] : project_ids.select { |id| id == project_id.to_i }
|
||||
end
|
||||
project_ids
|
||||
end
|
||||
end
|
||||
|
|
18
spec/controllers/search_controller_spec.rb
Normal file
18
spec/controllers/search_controller_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe SearchController do
|
||||
let(:project) { create(:project, public: true) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
describe '#find_project_ids' do
|
||||
it 'should include public projects ids when searching within a single project' do
|
||||
project_ids = controller.find_project_ids(nil, project.id)
|
||||
project_ids.size.should == 1
|
||||
project_ids[0].should == project.id
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue