Commit 1453d309 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix incorrect rendering of flash messages

Flash messages are not cleared unless they are accessed in
a request. Our JSON requests don't read the flash causing these
messages to persist to unrelated requests.

We fix this by only setting the flash message for non-AJAX
HTML requests.
parent 1d7bcbf3
...@@ -47,7 +47,7 @@ module RoutableActions ...@@ -47,7 +47,7 @@ module RoutableActions
canonical_path = routable.full_path canonical_path = routable.full_path
if canonical_path != requested_full_path if canonical_path != requested_full_path
if canonical_path.casecmp(requested_full_path) != 0 if !request.xhr? && request.format.html? && canonical_path.casecmp(requested_full_path) != 0
flash[:notice] = "#{routable.class.to_s.titleize} '#{requested_full_path}' was moved to '#{canonical_path}'. Please update any links and bookmarks that may still have the old path." flash[:notice] = "#{routable.class.to_s.titleize} '#{requested_full_path}' was moved to '#{canonical_path}'. Please update any links and bookmarks that may still have the old path."
end end
......
---
title: Fix "project or group was moved" alerts showing up in the wrong pages
merge_request: 18985
author:
type: fixed
...@@ -314,6 +314,24 @@ describe Groups::MilestonesController do ...@@ -314,6 +314,24 @@ describe Groups::MilestonesController do
expect(controller).to set_flash[:notice].to(group_moved_message(redirect_route, group)) expect(controller).to set_flash[:notice].to(group_moved_message(redirect_route, group))
end end
context 'with an AJAX request' do
it 'redirects to the canonical path but does not set flash message' do
get :merge_requests, params: { group_id: redirect_route.path, id: title }, xhr: true
expect(response).to redirect_to(merge_requests_group_milestone_path(group.to_param, title))
expect(controller).not_to set_flash[:notice]
end
end
context 'with JSON format' do
it 'redirects to the canonical path but does not set flash message' do
get :merge_requests, params: { group_id: redirect_route.path, id: title }, format: :json
expect(response).to redirect_to(merge_requests_group_milestone_path(group.to_param, title, format: :json))
expect(controller).not_to set_flash[:notice]
end
end
context 'when the old group path is a substring of the scheme or host' do context 'when the old group path is a substring of the scheme or host' do
let(:redirect_route) { group.redirect_routes.create(path: 'http') } let(:redirect_route) { group.redirect_routes.create(path: 'http') }
......
...@@ -204,6 +204,24 @@ describe Projects::LabelsController do ...@@ -204,6 +204,24 @@ describe Projects::LabelsController do
expect(response).to redirect_to(project_labels_path(project)) expect(response).to redirect_to(project_labels_path(project))
expect(controller).to set_flash[:notice].to(project_moved_message(redirect_route, project)) expect(controller).to set_flash[:notice].to(project_moved_message(redirect_route, project))
end end
context 'with an AJAX request' do
it 'redirects to the canonical path but does not set flash message' do
get :index, params: { namespace_id: project.namespace, project_id: project.to_param + 'old' }, xhr: true
expect(response).to redirect_to(project_labels_path(project))
expect(controller).not_to set_flash[:notice]
end
end
context 'with JSON format' do
it 'redirects to the canonical path but does not set flash message' do
get :index, params: { namespace_id: project.namespace, project_id: project.to_param + 'old' }, format: :json
expect(response).to redirect_to(project_labels_path(project, format: :json))
expect(controller).not_to set_flash[:notice]
end
end
end 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