Commit 5ad59e45 authored by Paul Gascou-Vaillancourt's avatar Paul Gascou-Vaillancourt Committed by Markus Koller

Add security nav tabs in a dedicated method

This slightly refactors the EE::ProjectsHelper#get_project_nav_tabs
method by moving the security nav tabs to a dedicated method to reduce
cyclometic and perceived complexity of the main method.
parent 58a10a6e
......@@ -25,27 +25,11 @@ module EE
]
end
# rubocop: disable Metrics/CyclomaticComplexity
override :get_project_nav_tabs
def get_project_nav_tabs(project, current_user)
nav_tabs = super
if can?(current_user, :read_project_security_dashboard, @project)
nav_tabs << :security
nav_tabs << :security_configuration
end
if can?(current_user, :read_dependencies, @project)
nav_tabs << :dependencies
end
if can?(current_user, :read_licenses, project)
nav_tabs << :licenses
end
if can?(current_user, :read_threat_monitoring, project)
nav_tabs << :threat_monitoring
end
nav_tabs += get_project_security_nav_tabs(project, current_user)
if ::Gitlab.config.packages.enabled &&
project.feature_available?(:packages) &&
......@@ -71,7 +55,6 @@ module EE
nav_tabs
end
# rubocop: enable Metrics/CyclomaticComplexity
override :tab_ability_map
def tab_ability_map
......@@ -286,5 +269,30 @@ module EE
def show_compliance_framework_badge?(project)
project&.compliance_framework_setting&.present?
end
private
def get_project_security_nav_tabs(project, current_user)
nav_tabs = []
if can?(current_user, :read_project_security_dashboard, project)
nav_tabs << :security
nav_tabs << :security_configuration
end
if can?(current_user, :read_dependencies, project)
nav_tabs << :dependencies
end
if can?(current_user, :read_licenses, project)
nav_tabs << :licenses
end
if can?(current_user, :read_threat_monitoring, project)
nav_tabs << :threat_monitoring
end
nav_tabs
end
end
end
......@@ -171,12 +171,12 @@ describe ProjectsHelper do
describe '#get_project_nav_tabs' do
using RSpec::Parameterized::TableSyntax
where(:ability, :nav_tab) do
:read_dependencies | :dependencies
:read_feature_flag | :operations
:read_licenses | :licenses
:read_project_security_dashboard | :security
:read_threat_monitoring | :threat_monitoring
where(:ability, :nav_tabs) do
:read_dependencies | [:dependencies]
:read_feature_flag | [:operations]
:read_licenses | [:licenses]
:read_project_security_dashboard | [:security, :security_configuration]
:read_threat_monitoring | [:threat_monitoring]
end
with_them do
......@@ -191,23 +191,23 @@ describe ProjectsHelper do
helper.send(:get_project_nav_tabs, project, user)
end
context 'when the feature is disabled' do
context 'when the feature is not available' do
before do
allow(helper).to receive(:can?).with(user, ability, project).and_return(false)
end
it 'does not include the nav tab' do
is_expected.not_to include(nav_tab)
it 'does not include the nav tabs' do
is_expected.not_to include(*nav_tabs)
end
end
context 'when threat monitoring is enabled' do
context 'when the feature is available' do
before do
allow(helper).to receive(:can?).with(user, ability, project).and_return(true)
end
it 'includes the nav tab' do
is_expected.to include(nav_tab)
it 'includes the nav tabs' do
is_expected.to include(*nav_tabs)
end
end
end
......
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