Commit 6495618a authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix redirects to issue sidebar JSON after sign in

request.xhr? is unreliable because the X-Requested-With header can be
missing if it is requested using `fetch`.

This changes the check to check for the HTML request format
parent e08deb07
...@@ -323,7 +323,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -323,7 +323,7 @@ class Projects::IssuesController < Projects::ApplicationController
end end
def store_uri def store_uri
if request.get? && !request.xhr? if request.get? && request.format.html?
store_location_for :user, request.fullpath store_location_for :user, request.fullpath
end end
end end
......
---
title: Fix redirects to issue sidebar JSON when visiting the login page
merge_request: 45194
author:
type: fixed
...@@ -388,15 +388,23 @@ RSpec.describe Projects::IssuesController do ...@@ -388,15 +388,23 @@ RSpec.describe Projects::IssuesController do
# Rails router. A controller-style spec matches the wrong route, and # Rails router. A controller-style spec matches the wrong route, and
# session['user_return_to'] becomes incorrect. # session['user_return_to'] becomes incorrect.
describe 'Redirect after sign in', type: :request do describe 'Redirect after sign in', type: :request do
context 'with an AJAX request' do before_all do
project.add_developer(user)
end
before do
login_as(user)
end
context 'with a JSON request' do
it 'does not store the visited URL' do it 'does not store the visited URL' do
get project_issue_path(project, issue), xhr: true get project_issue_path(project, issue, format: :json)
expect(session['user_return_to']).to be_blank expect(session['user_return_to']).to be_blank
end end
end end
context 'without an AJAX request' do context 'with an HTML request' do
it 'stores the visited URL' do it 'stores the visited URL' do
get project_issue_path(project, issue) get project_issue_path(project, issue)
......
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