Commit 3e25fb46 authored by rpereira2's avatar rpereira2

Change condition to display Metrics tab in sidebar

Display the metrics tab in the sidebar when the user has the
metrics_dashboard permission.
parent 2ac4384f
...@@ -410,7 +410,7 @@ module ProjectsHelper ...@@ -410,7 +410,7 @@ module ProjectsHelper
nav_tabs << :pipelines nav_tabs << :pipelines
end end
if can?(current_user, :read_environment, project) || can?(current_user, :read_cluster, project) if can_view_operations_tab?(current_user, project)
nav_tabs << :operations nav_tabs << :operations
end end
...@@ -438,22 +438,29 @@ module ProjectsHelper ...@@ -438,22 +438,29 @@ module ProjectsHelper
def tab_ability_map def tab_ability_map
{ {
environments: :read_environment, environments: :read_environment,
milestones: :read_milestone, metrics_dashboards: :metrics_dashboard,
snippets: :read_snippet, milestones: :read_milestone,
settings: :admin_project, snippets: :read_snippet,
builds: :read_build, settings: :admin_project,
clusters: :read_cluster, builds: :read_build,
serverless: :read_cluster, clusters: :read_cluster,
error_tracking: :read_sentry_issue, serverless: :read_cluster,
alert_management: :read_alert_management_alert, error_tracking: :read_sentry_issue,
labels: :read_label, alert_management: :read_alert_management_alert,
issues: :read_issue, labels: :read_label,
project_members: :read_project_member, issues: :read_issue,
wiki: :read_wiki project_members: :read_project_member,
wiki: :read_wiki
} }
end end
def can_view_operations_tab?(current_user, project)
[:read_environment, :read_cluster, :metrics_dashboard].any? do |ability|
can?(current_user, ability, project)
end
end
def search_tab_ability_map def search_tab_ability_map
@search_tab_ability_map ||= tab_ability_map.merge( @search_tab_ability_map ||= tab_ability_map.merge(
blobs: :download_code, blobs: :download_code,
......
...@@ -216,7 +216,7 @@ ...@@ -216,7 +216,7 @@
= _('Operations') = _('Operations')
%li.divider.fly-out-top-item %li.divider.fly-out-top-item
- if project_nav_tab? :environments - if project_nav_tab? :metrics_dashboards
= nav_link(controller: :environments, action: [:metrics, :metrics_redirect]) do = nav_link(controller: :environments, action: [:metrics, :metrics_redirect]) do
= link_to metrics_project_environments_path(@project), title: _('Metrics'), class: 'shortcuts-metrics', data: { qa_selector: 'operations_metrics_link' } do = link_to metrics_project_environments_path(@project), title: _('Metrics'), class: 'shortcuts-metrics', data: { qa_selector: 'operations_metrics_link' } do
%span %span
......
...@@ -5,6 +5,9 @@ require 'spec_helper' ...@@ -5,6 +5,9 @@ require 'spec_helper'
describe ProjectsHelper do describe ProjectsHelper do
include ProjectForksHelper include ProjectForksHelper
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
describe '#project_incident_management_setting' do describe '#project_incident_management_setting' do
let(:project) { create(:project) } let(:project) { create(:project) }
...@@ -500,6 +503,23 @@ describe ProjectsHelper do ...@@ -500,6 +503,23 @@ describe ProjectsHelper do
end end
end end
describe '#can_view_operations_tab?' do
before do
allow(helper).to receive(:current_user).and_return(user)
end
subject { helper.send(:can_view_operations_tab?, user, project) }
[:read_environment, :read_cluster, :metrics_dashboard].each do |ability|
it 'includes operations tab' do
allow(helper).to receive(:can?).and_return(false)
allow(helper).to receive(:can?).with(user, ability, project).and_return(true)
is_expected.to be(true)
end
end
end
describe '#show_projects' do describe '#show_projects' do
let(:projects) do let(:projects) do
create(:project) create(:project)
......
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