Commit 638869fa authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'rc/redirect_to_new_metrics_page' into 'master'

Redirect to new metrics dashboard page

See merge request gitlab-org/gitlab!38364
parents bb83206c 28e612cb
......@@ -161,18 +161,14 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end
def metrics_redirect
environment = project.default_environment
if environment
redirect_to environment_metrics_path(environment)
else
render :empty_metrics
end
redirect_to project_metrics_dashboard_path(project)
end
def metrics
respond_to do |format|
format.html
format.html do
redirect_to project_metrics_dashboard_path(project, environment: environment )
end
format.json do
# Currently, this acts as a hint to load the metrics details into the cache
# if they aren't there already
......
......@@ -22,7 +22,7 @@ module Projects
if environment
render 'projects/environments/metrics'
else
render_404
render 'projects/environments/empty_metrics'
end
end
......
......@@ -748,6 +748,7 @@ module ProjectsHelper
gcp
logs
product_analytics
metrics_dashboard
]
end
......
......@@ -223,8 +223,8 @@
%li.divider.fly-out-top-item
- 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
= nav_link(controller: :metrics_dashboard, action: [:show]) do
= link_to project_metrics_dashboard_path(@project), title: _('Metrics'), class: 'shortcuts-metrics', data: { qa_selector: 'operations_metrics_link' } do
%span
= _('Metrics')
......
---
title: Redirect to new metrics dashboard page
merge_request: 38364
author:
type: added
......@@ -348,34 +348,10 @@ RSpec.describe Projects::EnvironmentsController do
end
describe 'GET #metrics_redirect' do
it 'redirects to environment if it exists' do
it 'redirects to metrics dashboard page' do
get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project }
expect(response).to redirect_to(environment_metrics_path(environment))
end
context 'with anonymous user and public dashboard visibility' do
let(:project) { create(:project, :public) }
let(:user) { create(:user) }
it 'redirects successfully' do
project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED)
get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project }
expect(response).to redirect_to(environment_metrics_path(environment))
end
end
context 'when there are no environments' do
let(:environment) { }
it 'redirects to empty metrics page' do
get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project }
expect(response).to be_ok
expect(response).to render_template 'empty_metrics'
end
expect(response).to redirect_to(project_metrics_dashboard_path(project))
end
end
......@@ -385,12 +361,12 @@ RSpec.describe Projects::EnvironmentsController do
end
context 'when environment has no metrics' do
it 'returns a metrics page' do
it 'redirects to metrics dashboard page' do
expect(environment).not_to receive(:metrics)
get :metrics, params: environment_params
expect(response).to be_ok
expect(response).to redirect_to(project_metrics_dashboard_path(project, environment: environment))
end
context 'when requesting metrics as JSON' do
......@@ -440,12 +416,12 @@ RSpec.describe Projects::EnvironmentsController do
let(:project) { create(:project, :public) }
let(:user) { create(:user) }
it 'returns success' do
it 'redirects to metrics dashboard page' do
project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED)
get :metrics, params: environment_params
expect(response).to have_gitlab_http_status(:ok)
expect(response).to redirect_to(project_metrics_dashboard_path(project, environment: environment))
end
end
end
......
......@@ -28,9 +28,8 @@ RSpec.describe 'Environment > Metrics' do
shared_examples 'has environment selector' do
it 'has a working environment selector', :js do
click_link('See metrics')
# TODO: See metrics on the sidebar still points to the old metrics URL
# https://gitlab.com/gitlab-org/gitlab/-/issues/229277
expect(page).to have_current_path(metrics_project_environment_path(project, id: environment.id))
expect(page).to have_current_path(project_metrics_dashboard_path(project, environment: environment.id))
expect(page).to have_css('[data-qa-selector="environments_dropdown"]')
within('[data-qa-selector="environments_dropdown"]') do
......
......@@ -23,6 +23,22 @@ RSpec.describe 'metrics dashboard page' do
send_request
expect(assigns(:environment).id).to eq(environment.id)
end
context 'with anonymous user and public dashboard visibility' do
let(:anonymous_user) { create(:user) }
let(:project) do
create(:project, :public, metrics_dashboard_access_level: 'enabled')
end
before do
login_as(anonymous_user)
end
it 'returns 200' do
send_request
expect(response).to have_gitlab_http_status(:ok)
end
end
end
describe 'GET /:namespace/:project/-/metrics?environment=:environment.id' do
......
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