Commit 32474423 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'fj-clean-helpers-code-after-sidebar-refactor' into 'master'

Clean project helpers code after project sidebar refactor

See merge request gitlab-org/gitlab!61046
parents 794a20b0 f0f998fd
......@@ -125,34 +125,12 @@ module ProjectsHelper
project.fork_source if project.fork_source && can?(current_user, :read_project, project.fork_source)
end
def project_nav_tabs
@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
def any_project_nav_tab?(tabs)
tabs.any? { |tab| project_nav_tab?(tab) }
end
def project_for_deploy_key(deploy_key)
if deploy_key.has_access_to?(@project)
@project
else
deploy_key.projects.find do |project|
can?(current_user, :read_project, project)
end
end
end
def can_change_visibility_level?(project, current_user)
can?(current_user, :change_visibility_level, project)
end
......@@ -374,66 +352,6 @@ module ProjectsHelper
private
# rubocop:disable Metrics/CyclomaticComplexity
def get_project_nav_tabs(project, current_user)
nav_tabs = [:home]
unless project.empty_repo?
nav_tabs += [:files, :commits, :network, :graphs, :forks] if can?(current_user, :download_code, project)
nav_tabs << :releases if can?(current_user, :read_release, project)
end
if project.repo_exists? && can?(current_user, :read_merge_request, project)
nav_tabs << :merge_requests
end
if Gitlab.config.registry.enabled && can?(current_user, :read_container_image, project)
nav_tabs << :container_registry
end
if Feature.enabled?(:infrastructure_registry_page)
nav_tabs << :infrastructure_registry
end
# Pipelines feature is tied to presence of builds
if can?(current_user, :read_build, project)
nav_tabs << :pipelines
end
tab_ability_map.each do |tab, ability|
if can?(current_user, ability, project)
nav_tabs << tab
end
end
apply_external_nav_tabs(nav_tabs, project)
nav_tabs += package_nav_tabs(project, current_user)
nav_tabs << :learn_gitlab if learn_gitlab_experiment_enabled?(project)
nav_tabs
end
# rubocop:enable Metrics/CyclomaticComplexity
def package_nav_tabs(project, current_user)
[].tap do |tabs|
if ::Gitlab.config.packages.enabled && can?(current_user, :read_package, project)
tabs << :packages
end
end
end
def apply_external_nav_tabs(nav_tabs, project)
nav_tabs << :external_issue_tracker if project.external_issue_tracker
nav_tabs << :external_wiki if project.external_wiki
if project.has_confluence?
nav_tabs.delete(:wiki)
nav_tabs << :confluence
end
end
def tab_ability_map
{
cycle_analytics: :read_cycle_analytics,
......
-# We're migration the project sidebar to a logical model based structure. If you need to update
-# any of the existing menus, you can find them in app/views/layouts/nav/sidebar/_project_menus.html.haml.
= render partial: 'shared/nav/sidebar', object: Sidebars::Projects::Panel.new(project_sidebar_context(@project, current_user, current_ref))
......@@ -12,37 +12,6 @@ module EE
]
end
override :get_project_nav_tabs
def get_project_nav_tabs(project, current_user)
nav_tabs = super
if can?(current_user, :read_code_review_analytics, project)
nav_tabs << :code_review
end
if can?(current_user, :read_project_merge_request_analytics, project)
nav_tabs << :merge_request_analytics
end
if project.feature_available?(:issues_analytics) && can?(current_user, :read_project, project)
nav_tabs << :issues_analytics
end
if project.insights_available?
nav_tabs << :project_insights
end
if can?(current_user, :read_requirement, project)
nav_tabs << :requirements
end
if can?(current_user, :read_incident_management_oncall_schedule, project)
nav_tabs << :oncall_schedule
end
nav_tabs
end
override :project_permissions_settings
def project_permissions_settings(project)
settings = super.merge(
......@@ -249,10 +218,6 @@ module EE
end
end
def any_project_nav_tab?(tabs)
tabs.any? { |tab| project_nav_tab?(tab) }
end
def show_discover_project_security?(project)
!!current_user &&
::Gitlab.com? &&
......
......@@ -390,93 +390,6 @@ RSpec.describe ProjectsHelper do
end
end
describe '#get_project_nav_tabs' do
before do
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?) { true }
end
subject do
helper.send(:get_project_nav_tabs, project, user)
end
context 'when builds feature is enabled' do
before do
allow(project).to receive(:builds_enabled?).and_return(true)
end
it "does include pipelines tab" do
is_expected.to include(:pipelines)
end
end
context 'when builds feature is disabled' do
before do
allow(project).to receive(:builds_enabled?).and_return(false)
end
context 'when user has access to builds' do
it "does include pipelines tab" do
is_expected.to include(:pipelines)
end
end
context 'when user does not have access to builds' do
before do
allow(helper).to receive(:can?) { false }
end
it "does not include pipelines tab" do
is_expected.not_to include(:pipelines)
end
end
end
context 'when project has external wiki' do
it 'includes external wiki tab' do
project.create_external_wiki_service(active: true, properties: { 'external_wiki_url' => 'https://gitlab.com' })
project.reload
is_expected.to include(:external_wiki)
end
end
context 'when project does not have external wiki' do
it 'does not include external wiki tab' do
expect(project.external_wiki).to be_nil
is_expected.not_to include(:external_wiki)
end
end
context 'when project has confluence enabled' do
before do
allow(project).to receive(:has_confluence?).and_return(true)
end
it { is_expected.to include(:confluence) }
it { is_expected.not_to include(:wiki) }
end
context 'when project does not have confluence enabled' do
it { is_expected.not_to include(:confluence) }
it { is_expected.to include(:wiki) }
end
context 'learn gitlab experiment' do
context 'when it is enabled' do
before do
expect(helper).to receive(:learn_gitlab_experiment_enabled?).with(project).and_return(true)
end
it { is_expected.to include(:learn_gitlab) }
end
context 'when it is not enabled' do
it { is_expected.not_to include(:learn_gitlab) }
end
end
end
describe '#show_projects' do
let(:projects) do
Project.all
......
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