Commit 26c801fa authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '61453-helpers-ee' into 'master'

EE port: Make external_dashboard_url available to frontend

See merge request gitlab-org/gitlab-ee!12345
parents 7682163b ae93c4e1
......@@ -32,7 +32,8 @@ module EnvironmentsHelper
"environments-endpoint": project_environments_path(project, format: :json),
"project-path" => project_path(project),
"tags-path" => project_tags_path(project),
"has-metrics" => "#{environment.has_metrics?}"
"has-metrics" => "#{environment.has_metrics?}",
"external-dashboard-url" => project.metrics_setting_external_dashboard_url
}
end
end
......@@ -321,6 +321,10 @@ module ProjectsHelper
Ability.allowed?(current_user, :admin_project_member, @project)
end
def metrics_external_dashboard_url
@project.metrics_setting_external_dashboard_url
end
private
def get_project_nav_tabs(project, current_user)
......
......@@ -309,6 +309,7 @@ class Project < ApplicationRecord
delegate :group_clusters_enabled?, to: :group, allow_nil: true
delegate :root_ancestor, to: :namespace, allow_nil: true
delegate :last_pipeline, to: :commit, allow_nil: true
delegate :external_dashboard_url, to: :metrics_setting, allow_nil: true, prefix: true
# Validations
validates :creator, presence: true, on: :create
......
.js-operation-settings{ data: { external_dashboard: { path: '',
.js-operation-settings{ data: { external_dashboard: { path: metrics_external_dashboard_url,
help_page_path: help_page_path('user/project/operations/link_to_external_dashboard') } } }
......@@ -20,36 +20,14 @@ describe EnvironmentsHelper do
.and_return(true)
end
it 'contains all keys' do
it 'returns additional configuration' do
expect(subject).to include(
'settings-path' => edit_project_service_path(project, 'prometheus'),
'clusters-path' => project_clusters_path(project),
'current-environment-name': environment.name,
'documentation-path' => help_page_path('administration/monitoring/prometheus/index.md'),
'empty-getting-started-svg-path' => match_asset_path('/assets/illustrations/monitoring/getting_started.svg'),
'empty-loading-svg-path' => match_asset_path('/assets/illustrations/monitoring/loading.svg'),
'empty-no-data-svg-path' => match_asset_path('/assets/illustrations/monitoring/no_data.svg'),
'empty-unable-to-connect-svg-path' => match_asset_path('/assets/illustrations/monitoring/unable_to_connect.svg'),
'metrics-endpoint' => additional_metrics_project_environment_path(project, environment, format: :json),
'deployment-endpoint' => project_environment_deployments_path(project, environment, format: :json),
'environments-endpoint': project_environments_path(project, format: :json),
'project-path' => project_path(project),
'tags-path' => project_tags_path(project),
'has-metrics' => "#{environment.has_metrics?}",
'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'
)
expect(subject.keys).to contain_exactly(
'settings-path', 'clusters-path', :'current-environment-name', 'documentation-path',
'empty-getting-started-svg-path', 'empty-loading-svg-path', 'empty-no-data-svg-path',
'empty-unable-to-connect-svg-path', 'metrics-endpoint', 'deployment-endpoint',
:'environments-endpoint', 'project-path', 'tags-path', 'has-metrics', 'custom-metrics-path',
'validate-query-path', 'custom-metrics-available', 'alerts-endpoint', 'prometheus-alerts-available'
)
end
end
......
# frozen_string_literal: true
require 'spec_helper'
describe EnvironmentsHelper do
set(:environment) { create(:environment) }
set(:project) { environment.project }
set(:user) { create(:user) }
describe '#metrics_data' do
before do
# This is so that this spec also passes in EE.
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?).and_return(true)
end
let(:metrics_data) { helper.metrics_data(project, environment) }
it 'returns data' do
expect(metrics_data).to include(
'settings-path' => edit_project_service_path(project, 'prometheus'),
'clusters-path' => project_clusters_path(project),
'current-environment-name': environment.name,
'documentation-path' => help_page_path('administration/monitoring/prometheus/index.md'),
'empty-getting-started-svg-path' => match_asset_path('/assets/illustrations/monitoring/getting_started.svg'),
'empty-loading-svg-path' => match_asset_path('/assets/illustrations/monitoring/loading.svg'),
'empty-no-data-svg-path' => match_asset_path('/assets/illustrations/monitoring/no_data.svg'),
'empty-unable-to-connect-svg-path' => match_asset_path('/assets/illustrations/monitoring/unable_to_connect.svg'),
'metrics-endpoint' => additional_metrics_project_environment_path(project, environment, format: :json),
'deployment-endpoint' => project_environment_deployments_path(project, environment, format: :json),
'environments-endpoint': project_environments_path(project, format: :json),
'project-path' => project_path(project),
'tags-path' => project_tags_path(project),
'has-metrics' => "#{environment.has_metrics?}",
'external-dashboard-url' => nil
)
end
context 'with metrics_setting' do
before do
create(:project_metrics_setting, project: project, external_dashboard_url: 'http://gitlab.com')
end
it 'adds external_dashboard_url' do
expect(metrics_data['external-dashboard-url']).to eq('http://gitlab.com')
end
end
end
end
......@@ -819,4 +819,26 @@ describe ProjectsHelper do
expect(helper.can_import_members?).to eq true
end
end
describe '#metrics_external_dashboard_url' do
let(:project) { create(:project) }
before do
helper.instance_variable_set(:@project, project)
end
context 'metrics_setting exists' do
it 'returns external_dashboard_url' do
metrics_setting = create(:project_metrics_setting, project: project)
expect(helper.metrics_external_dashboard_url).to eq(metrics_setting.external_dashboard_url)
end
end
context 'metrics_setting does not exist' do
it 'returns nil' do
expect(helper.metrics_external_dashboard_url).to eq(nil)
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