Commit be9ffbaf authored by Valery Sizov's avatar Valery Sizov

Create a separate helper to check if we show particular tab on a search page

parent 1a424a9b
...@@ -85,6 +85,12 @@ module ProjectsHelper ...@@ -85,6 +85,12 @@ module ProjectsHelper
@nav_tabs ||= get_project_nav_tabs(@project, current_user) @nav_tabs ||= get_project_nav_tabs(@project, current_user)
end end
def project_search_tabs?(tab)
abilities = Array(search_tab_ability_map[tab])
abilities.any? { |ability| can?(current_user, ability, @project) }
end
def project_nav_tab?(name) def project_nav_tab?(name)
project_nav_tabs.include? name project_nav_tabs.include? name
end end
...@@ -203,7 +209,17 @@ module ProjectsHelper ...@@ -203,7 +209,17 @@ module ProjectsHelper
nav_tabs << :container_registry nav_tabs << :container_registry
end end
tab_ability_map = { tab_ability_map.each do |tab, ability|
if can?(current_user, ability, project)
nav_tabs << tab
end
end
nav_tabs.flatten
end
def tab_ability_map
{
environments: :read_environment, environments: :read_environment,
milestones: :read_milestone, milestones: :read_milestone,
pipelines: :read_pipeline, pipelines: :read_pipeline,
...@@ -215,14 +231,15 @@ module ProjectsHelper ...@@ -215,14 +231,15 @@ module ProjectsHelper
team: :read_project_member, team: :read_project_member,
wiki: :read_wiki wiki: :read_wiki
} }
end
tab_ability_map.each do |tab, ability| def search_tab_ability_map
if can?(current_user, ability, project) @search_tab_ability_map ||= tab_ability_map.merge(
nav_tabs << tab blobs: :download_code,
end commits: :download_code,
end merge_requests: :read_merge_request,
notes: [:read_merge_request, :download_code, :read_issue, :read_project_snippet]
nav_tabs.flatten )
end end
def project_lfs_status(project) def project_lfs_status(project)
......
...@@ -33,12 +33,6 @@ module SearchHelper ...@@ -33,12 +33,6 @@ module SearchHelper
def parse_search_result(result) def parse_search_result(result)
Gitlab::ProjectSearchResults.parse_search_result(result) Gitlab::ProjectSearchResults.parse_search_result(result)
end end
def show_notes_tab?
[:read_merge_request, :download_code, :read_issue, :read_project_snippet].all? do |ability|
can?(current_user, :read_merge_request, @project)
end
end
private private
......
...@@ -3,43 +3,43 @@ ...@@ -3,43 +3,43 @@
.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
- if can?(current_user, :download_code, @project) - if project_search_tabs?(:blobs)
%li{ class: active_when(@scope == 'blobs') } %li{ class: active_when(@scope == 'blobs') }
= link_to search_filter_path(scope: 'blobs') do = link_to search_filter_path(scope: 'blobs') do
Code Code
%span.badge %span.badge
= @search_results.blobs_count = @search_results.blobs_count
- if can?(current_user, :read_issue, @project) - if project_search_tabs?(:issues)
%li{ class: active_when(@scope == 'issues') } %li{ class: active_when(@scope == 'issues') }
= link_to search_filter_path(scope: 'issues') do = link_to search_filter_path(scope: 'issues') do
Issues Issues
%span.badge %span.badge
= @search_results.issues_count = @search_results.issues_count
- if can?(current_user, :read_merge_request, @project) - if project_search_tabs?(:merge_requests)
%li{ class: active_when(@scope == 'merge_requests') } %li{ class: active_when(@scope == 'merge_requests') }
= link_to search_filter_path(scope: 'merge_requests') do = link_to search_filter_path(scope: 'merge_requests') do
Merge requests Merge requests
%span.badge %span.badge
= @search_results.merge_requests_count = @search_results.merge_requests_count
- if can?(current_user, :read_milestone, @project) - if project_search_tabs?(:milestones)
%li{ class: active_when(@scope == 'milestones') } %li{ class: active_when(@scope == 'milestones') }
= link_to search_filter_path(scope: 'milestones') do = link_to search_filter_path(scope: 'milestones') do
Milestones Milestones
%span.badge %span.badge
= @search_results.milestones_count = @search_results.milestones_count
- if show_notes_tab? - if project_search_tabs?(:notes)
%li{ class: active_when(@scope == 'notes') } %li{ class: active_when(@scope == 'notes') }
= link_to search_filter_path(scope: 'notes') do = link_to search_filter_path(scope: 'notes') do
Comments Comments
%span.badge %span.badge
= @search_results.notes_count = @search_results.notes_count
- if can?(current_user, :read_wiki, @project) - if project_search_tabs?(:wiki)
%li{ class: active_when(@scope == 'wiki_blobs') } %li{ class: active_when(@scope == 'wiki_blobs') }
= link_to search_filter_path(scope: 'wiki_blobs') do = link_to search_filter_path(scope: 'wiki_blobs') do
Wiki Wiki
%span.badge %span.badge
= @search_results.wiki_blobs_count = @search_results.wiki_blobs_count
- if can?(current_user, :download_code, @project) - if project_search_tabs?(:commits)
%li{ class: active_when(@scope == 'commits') } %li{ class: active_when(@scope == 'commits') }
= link_to search_filter_path(scope: 'commits') do = link_to search_filter_path(scope: 'commits') do
Commits Commits
......
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