Commit 33077789 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'mwaw/remove_logs_path_for_not_authorised_users' into 'master'

Remove un accessible links from embded dashboards context menu

Closes #207184

See merge request gitlab-org/gitlab!25892
parents b0a8ed84 0a1160cb
---
title: Remove unreachable link from embded dashboard context menu
merge_request: 25892
author:
type: fixed
...@@ -45,9 +45,9 @@ module EE ...@@ -45,9 +45,9 @@ module EE
"validate-query-path" => validate_query_project_prometheus_metrics_path(project), "validate-query-path" => validate_query_project_prometheus_metrics_path(project),
"custom-metrics-available" => "#{custom_metrics_available?(project)}", "custom-metrics-available" => "#{custom_metrics_available?(project)}",
"alerts-endpoint" => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json), "alerts-endpoint" => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
"prometheus-alerts-available" => "#{can?(current_user, :read_prometheus_alerts, project)}", "prometheus-alerts-available" => "#{can?(current_user, :read_prometheus_alerts, project)}"
"logs_path" => project_logs_path(project, environment_name: environment.name)
} }
ee_metrics_data["logs_path"] = project_logs_path(project, environment_name: environment.name) if can?(current_user, :read_pod_logs, project)
super.merge(ee_metrics_data) super.merge(ee_metrics_data)
end end
......
...@@ -10,25 +10,49 @@ describe EnvironmentsHelper do ...@@ -10,25 +10,49 @@ describe EnvironmentsHelper do
describe '#metrics_data' do describe '#metrics_data' do
subject { helper.metrics_data(project, environment) } subject { helper.metrics_data(project, environment) }
before do context 'user has all accesses' do
allow(helper).to receive(:current_user).and_return(user) before do
allow(helper).to receive(:can?) allow(helper).to receive(:current_user).and_return(user)
.with(user, :read_prometheus_alerts, project) allow(helper).to receive(:can?)
.and_return(true) .with(user, :read_prometheus_alerts, project)
allow(helper).to receive(:can?) .and_return(true)
.with(user, :admin_project, project) allow(helper).to receive(:can?)
.and_return(true) .with(user, :admin_project, project)
.and_return(true)
allow(helper).to receive(:can?)
.with(user, :read_pod_logs, project)
.and_return(true)
end
it 'returns additional configuration' do
expect(subject).to include(
'custom-metrics-path' => project_prometheus_metrics_path(project),
'validate-query-path' => validate_query_project_prometheus_metrics_path(project),
'custom-metrics-available' => 'false',
'alerts-endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
'prometheus-alerts-available' => 'true',
'logs_path' => project_logs_path(project, environment_name: environment.name)
)
end
end end
it 'returns additional configuration' do context 'user does not have access to pod logs' do
expect(subject).to include( before do
'custom-metrics-path' => project_prometheus_metrics_path(project), allow(helper).to receive(:current_user).and_return(user)
'validate-query-path' => validate_query_project_prometheus_metrics_path(project), allow(helper).to receive(:can?)
'custom-metrics-available' => 'false', .with(user, :read_prometheus_alerts, project)
'alerts-endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json), .and_return(true)
'prometheus-alerts-available' => 'true', allow(helper).to receive(:can?)
'logs_path' => project_logs_path(project, environment_name: environment.name) .with(user, :admin_project, project)
) .and_return(true)
allow(helper).to receive(:can?)
.with(user, :read_pod_logs, project)
.and_return(false)
end
it 'returns additional configuration' do
expect(subject.keys).not_to include('logs_path')
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