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