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
nav_tabs << :pipelines
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
end
......@@ -438,22 +438,29 @@ module ProjectsHelper
def tab_ability_map
{
environments: :read_environment,
milestones: :read_milestone,
snippets: :read_snippet,
settings: :admin_project,
builds: :read_build,
clusters: :read_cluster,
serverless: :read_cluster,
error_tracking: :read_sentry_issue,
alert_management: :read_alert_management_alert,
labels: :read_label,
issues: :read_issue,
project_members: :read_project_member,
wiki: :read_wiki
environments: :read_environment,
metrics_dashboards: :metrics_dashboard,
milestones: :read_milestone,
snippets: :read_snippet,
settings: :admin_project,
builds: :read_build,
clusters: :read_cluster,
serverless: :read_cluster,
error_tracking: :read_sentry_issue,
alert_management: :read_alert_management_alert,
labels: :read_label,
issues: :read_issue,
project_members: :read_project_member,
wiki: :read_wiki
}
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
@search_tab_ability_map ||= tab_ability_map.merge(
blobs: :download_code,
......
......@@ -216,7 +216,7 @@
= _('Operations')
%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
= link_to metrics_project_environments_path(@project), title: _('Metrics'), class: 'shortcuts-metrics', data: { qa_selector: 'operations_metrics_link' } do
%span
......
......@@ -5,6 +5,9 @@ require 'spec_helper'
describe ProjectsHelper do
include ProjectForksHelper
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
describe '#project_incident_management_setting' do
let(:project) { create(:project) }
......@@ -500,6 +503,23 @@ describe ProjectsHelper do
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
let(:projects) do
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