Commit 7c845791 authored by rpereira2's avatar rpereira2

Keep existing parameters when redirecting dashboard

Keep any existing query parameters, and add the environment parameter.
parent 3c0f28c6
......@@ -18,7 +18,13 @@ module Projects
if environment
render 'projects/environments/metrics'
elsif default_environment
redirect_to project_metrics_dashboard_path(project, environment: default_environment)
redirect_to project_metrics_dashboard_path(
project,
**permitted_params
.to_h
.symbolize_keys
.merge(environment: default_environment)
)
else
render 'projects/environments/empty_metrics'
end
......@@ -26,9 +32,14 @@ module Projects
private
def permitted_params
@permitted_params ||= params.permit(:dashboard_path, :environment, :page)
end
def environment
strong_memoize(:environment) do
project.environments.find(params[:environment]) if params[:environment]
env = permitted_params[:environment]
project.environments.find(env) if env
end
end
......
......@@ -14,7 +14,7 @@ RSpec.describe 'Projects::MetricsDashboardController' do
end
describe 'GET /:namespace/:project/-/metrics' do
it 'returns 200' do
it "redirects to default environment's metrics dashboard" do
send_request
expect(response).to redirect_to(dashboard_route(environment: environment))
end
......@@ -24,6 +24,18 @@ RSpec.describe 'Projects::MetricsDashboardController' do
expect(assigns(:default_environment).id).to eq(environment.id)
end
it 'retains existing parameters when redirecting' do
get "#{dashboard_route(dashboard_path: '.gitlab/dashboards/dashboard_path.yml')}/panel/new"
expect(response).to redirect_to(
dashboard_route(
dashboard_path: '.gitlab/dashboards/dashboard_path.yml',
page: 'panel/new',
environment: environment
)
)
end
context 'with anonymous user and public dashboard visibility' do
let(:anonymous_user) { create(:user) }
let(:project) 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