Commit c8ee259d authored by rpereira2's avatar rpereira2

Move metrics helper out of EE

Since custom metrics is moving into Core, move the custom metrics
helper function out of EE.
parent 92d4d9bf
......@@ -18,6 +18,10 @@ module EnvironmentsHelper
}
end
def custom_metrics_available?(project)
can?(current_user, :admin_project, project)
end
def metrics_data(project, environment)
{
"settings-path" => edit_project_service_path(project, 'prometheus'),
......@@ -39,7 +43,10 @@ module EnvironmentsHelper
"has-metrics" => "#{environment.has_metrics?}",
"prometheus-status" => "#{environment.prometheus_status}",
"external-dashboard-url" => project.metrics_setting_external_dashboard_url,
"environment-state" => "#{environment.state}"
"environment-state" => "#{environment.state}",
"custom-metrics-path" => project_prometheus_metrics_path(project),
"validate-query-path" => validate_query_project_prometheus_metrics_path(project),
"custom-metrics-available" => "#{custom_metrics_available?(project)}"
}
end
......
......@@ -26,15 +26,8 @@ module EE
super.merge(ee_environments_folder_list_view_data)
end
def custom_metrics_available?(project)
can?(current_user, :admin_project, project)
end
def metrics_data(project, environment)
ee_metrics_data = {
"custom-metrics-path" => project_prometheus_metrics_path(project),
"validate-query-path" => validate_query_project_prometheus_metrics_path(project),
"custom-metrics-available" => "#{custom_metrics_available?(project)}",
"alerts-endpoint" => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
"prometheus-alerts-available" => "#{can?(current_user, :read_prometheus_alerts, project)}"
}
......
......@@ -26,9 +26,6 @@ describe EnvironmentsHelper do
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' => 'true',
'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)
......@@ -72,22 +69,4 @@ describe EnvironmentsHelper do
)
end
end
describe '#custom_metrics_available?' do
subject { helper.custom_metrics_available?(project) }
before do
project.add_maintainer(user)
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?)
.with(user, :admin_project, project)
.and_return(true)
end
it 'returns true' do
expect(subject).to eq(true)
end
end
end
......@@ -34,7 +34,10 @@ describe EnvironmentsHelper do
'has-metrics' => "#{environment.has_metrics?}",
'prometheus-status' => "#{environment.prometheus_status}",
'external-dashboard-url' => nil,
'environment-state' => environment.state
'environment-state' => environment.state,
'custom-metrics-path' => project_prometheus_metrics_path(project),
'validate-query-path' => validate_query_project_prometheus_metrics_path(project),
'custom-metrics-available' => 'true'
)
end
......@@ -58,4 +61,22 @@ describe EnvironmentsHelper do
it { is_expected.to include('environment-state' => 'stopped') }
end
end
describe '#custom_metrics_available?' do
subject { helper.custom_metrics_available?(project) }
before do
project.add_maintainer(user)
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?)
.with(user, :admin_project, project)
.and_return(true)
end
it 'returns true' do
expect(subject).to eq(true)
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