Commit 893b1eb1 authored by Valery Sizov's avatar Valery Sizov

Fix: Wiki is not searchable with Guest permissions

parent 72119e7f
...@@ -12,7 +12,7 @@ class SearchService ...@@ -12,7 +12,7 @@ class SearchService
@project = @project =
if params[:project_id].present? if params[:project_id].present?
the_project = Project.find_by(id: params[:project_id]) the_project = Project.find_by(id: params[:project_id])
can?(current_user, :download_code, the_project) ? the_project : nil can?(current_user, :read_project, the_project) ? the_project : nil
else else
nil nil
end end
......
...@@ -3,41 +3,48 @@ ...@@ -3,41 +3,48 @@
.fade-right= icon('angle-right') .fade-right= icon('angle-right')
%ul.nav-links.search-filter.scrolling-tabs %ul.nav-links.search-filter.scrolling-tabs
- if @project - if @project
%li{ class: active_when(@scope == 'blobs') } - if can?(current_user, :download_code, @project)
= link_to search_filter_path(scope: 'blobs') do %li{ class: active_when(@scope == 'blobs') }
Code = link_to search_filter_path(scope: 'blobs') do
%span.badge Code
= @search_results.blobs_count %span.badge
%li{ class: active_when(@scope == 'issues') } = @search_results.blobs_count
= link_to search_filter_path(scope: 'issues') do - if can?(current_user, :read_issue, @project)
Issues %li{ class: active_when(@scope == 'issues') }
%span.badge = link_to search_filter_path(scope: 'issues') do
= @search_results.issues_count Issues
%li{ class: active_when(@scope == 'merge_requests') } %span.badge
= link_to search_filter_path(scope: 'merge_requests') do = @search_results.issues_count
Merge requests - if can?(current_user, :read_merge_request, @project)
%span.badge %li{ class: active_when(@scope == 'merge_requests') }
= @search_results.merge_requests_count = link_to search_filter_path(scope: 'merge_requests') do
%li{ class: active_when(@scope == 'milestones') } Merge requests
= link_to search_filter_path(scope: 'milestones') do %span.badge
Milestones = @search_results.merge_requests_count
%span.badge - if can?(current_user, :read_milestone, @project)
= @search_results.milestones_count %li{ class: active_when(@scope == 'milestones') }
%li{ class: active_when(@scope == 'notes') } = link_to search_filter_path(scope: 'milestones') do
= link_to search_filter_path(scope: 'notes') do Milestones
Comments %span.badge
%span.badge = @search_results.milestones_count
= @search_results.notes_count - if can?(current_user, :read_merge_request, @project) || can?(current_user, :read_issue, @project)
%li{ class: active_when(@scope == 'wiki_blobs') } %li{ class: active_when(@scope == 'notes') }
= link_to search_filter_path(scope: 'wiki_blobs') do = link_to search_filter_path(scope: 'notes') do
Wiki Comments
%span.badge %span.badge
= @search_results.wiki_blobs_count = @search_results.notes_count
%li{ class: active_when(@scope == 'commits') } - if can?(current_user, :read_wiki, @project)
= link_to search_filter_path(scope: 'commits') do %li{ class: active_when(@scope == 'wiki_blobs') }
Commits = link_to search_filter_path(scope: 'wiki_blobs') do
%span.badge Wiki
= @search_results.commits_count %span.badge
= @search_results.wiki_blobs_count
- if can?(current_user, :download_code, @project)
%li{ class: active_when(@scope == 'commits') }
= link_to search_filter_path(scope: 'commits') do
Commits
%span.badge
= @search_results.commits_count
- elsif @show_snippets - elsif @show_snippets
%li{ class: active_when(@scope == 'snippet_blobs') } %li{ class: active_when(@scope == 'snippet_blobs') }
......
...@@ -26,6 +26,15 @@ describe SearchService, services: true do ...@@ -26,6 +26,15 @@ describe SearchService, services: true do
expect(project).to eq accessible_project expect(project).to eq accessible_project
end end
it 'returns the project for guests' do
search_project = create :empty_project
search_project.team << [user, :guest]
project = SearchService.new(user, project_id: search_project.id).project
expect(project).to eq search_project
end
end end
context 'when the project is not accessible' do context 'when the project is not accessible' 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