From 1a424a9bc9cf1fbabd70ac2384978ae94674e6d7 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Tue, 23 May 2017 13:40:18 +0300 Subject: Explicitly test that guest is able to search through the wiki --- app/helpers/search_helper.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/helpers') diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 9c46035057f..9021525784d 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -33,6 +33,12 @@ module SearchHelper def parse_search_result(result) Gitlab::ProjectSearchResults.parse_search_result(result) 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 -- cgit v1.2.1 From be9ffbafbba1b105bba3102cf7b5d93296478223 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Mon, 29 May 2017 16:52:02 +0300 Subject: Create a separate helper to check if we show particular tab on a search page --- app/helpers/projects_helper.rb | 33 +++++++++++++++++++++++++-------- app/helpers/search_helper.rb | 6 ------ 2 files changed, 25 insertions(+), 14 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 98bbcfaaba5..835473430c8 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -85,6 +85,12 @@ module ProjectsHelper @nav_tabs ||= get_project_nav_tabs(@project, current_user) 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) project_nav_tabs.include? name end @@ -203,7 +209,17 @@ module ProjectsHelper nav_tabs << :container_registry 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, milestones: :read_milestone, pipelines: :read_pipeline, @@ -215,14 +231,15 @@ module ProjectsHelper team: :read_project_member, wiki: :read_wiki } + end - tab_ability_map.each do |tab, ability| - if can?(current_user, ability, project) - nav_tabs << tab - end - end - - nav_tabs.flatten + def search_tab_ability_map + @search_tab_ability_map ||= tab_ability_map.merge( + blobs: :download_code, + commits: :download_code, + merge_requests: :read_merge_request, + notes: [:read_merge_request, :download_code, :read_issue, :read_project_snippet] + ) end def project_lfs_status(project) diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 9021525784d..9c46035057f 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -33,12 +33,6 @@ module SearchHelper def parse_search_result(result) Gitlab::ProjectSearchResults.parse_search_result(result) 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 -- cgit v1.2.1