Skip to content

Commit 8cf0eec

Browse files
committed
Chore(config): Stop respecting old configuration
`Spree::Config#redirect_back_on_unauthorized` has been removed in Solidus 3.0, and we're on 4.4 now. This can all go. If users have followed the deprecation warnings, then they should be fine with using `redirect_back`. Note that we're not using redirect_back in the admin, as logging out redirects to the admin root controller, which in turn redirects back, leading to an infinite redirect. Infinite redirects are no good.
1 parent 361b739 commit 8cf0eec

File tree

3 files changed

+4
-65
lines changed

3 files changed

+4
-65
lines changed

Diff for: lib/spree/auth/engine.rb

+4-39
Original file line numberDiff line numberDiff line change
@@ -28,65 +28,30 @@ class Engine < Rails::Engine
2828
ApplicationController.include Spree::AuthenticationHelpers
2929
end
3030

31-
def self.redirect_back_on_unauthorized?
32-
return false unless Spree::Config.respond_to?(:redirect_back_on_unauthorized)
33-
34-
if Spree::Config.redirect_back_on_unauthorized
35-
true
36-
else
37-
Spree::Deprecation.warn <<-WARN.strip_heredoc, caller
38-
Having Spree::Config.redirect_back_on_unauthorized set
39-
to `false` is deprecated and will not be supported in Solidus 3.0.
40-
Please change this configuration to `true` and be sure that your
41-
application does not break trying to redirect back when there is
42-
an unauthorized access.
43-
WARN
44-
45-
false
46-
end
47-
end
48-
4931
def self.prepare_backend
5032
Spree::Admin::BaseController.unauthorized_redirect = -> do
5133
if spree_current_user
5234
flash[:error] = I18n.t('spree.authorization_failure')
5335

54-
if Spree::Auth::Engine.redirect_back_on_unauthorized?
55-
redirect_back(fallback_location: spree.admin_unauthorized_path)
56-
else
57-
redirect_to spree.admin_unauthorized_path
58-
end
36+
redirect_to(spree.admin_unauthorized_path)
5937
else
6038
store_location
6139

62-
if Spree::Auth::Engine.redirect_back_on_unauthorized?
63-
redirect_back(fallback_location: spree.admin_login_path)
64-
else
65-
redirect_to spree.admin_login_path
66-
end
40+
redirect_to(spree.admin_login_path)
6741
end
6842
end
6943
end
7044

71-
7245
def self.prepare_frontend
7346
Spree::BaseController.unauthorized_redirect = -> do
7447
if spree_current_user
7548
flash[:error] = I18n.t('spree.authorization_failure')
7649

77-
if Spree::Auth::Engine.redirect_back_on_unauthorized?
78-
redirect_back(fallback_location: spree.unauthorized_path)
79-
else
80-
redirect_to spree.unauthorized_path
81-
end
50+
redirect_back(fallback_location: spree.unauthorized_path)
8251
else
8352
store_location
8453

85-
if Spree::Auth::Engine.redirect_back_on_unauthorized?
86-
redirect_back(fallback_location: spree.login_path)
87-
else
88-
redirect_to spree.login_path
89-
end
54+
redirect_back(fallback_location: spree.login_path)
9055
end
9156
end
9257
end

Diff for: spec/controllers/spree/admin/base_controller_spec.rb

-22
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
def index; authorize!(:read, :something); end
99
end
1010

11-
before do
12-
stub_spree_preferences(Spree::Config, redirect_back_on_unauthorized: true)
13-
end
14-
1511
context "when user is logged in" do
1612
before { sign_in(create(:user)) }
1713

@@ -21,15 +17,6 @@ def index; authorize!(:read, :something); end
2117
expect(response).to redirect_to(spree.admin_unauthorized_path)
2218
end
2319
end
24-
25-
context "when http_referrer is present" do
26-
before { request.env['HTTP_REFERER'] = '/redirect' }
27-
28-
it "redirects back" do
29-
get :index
30-
expect(response).to redirect_to('/redirect')
31-
end
32-
end
3320
end
3421

3522
context "when user is not logged in" do
@@ -39,15 +26,6 @@ def index; authorize!(:read, :something); end
3926
expect(response).to redirect_to(spree.admin_login_path)
4027
end
4128
end
42-
43-
context "when http_referrer is present" do
44-
before { request.env['HTTP_REFERER'] = '/redirect' }
45-
46-
it "redirects back" do
47-
get :index
48-
expect(response).to redirect_to('/redirect')
49-
end
50-
end
5129
end
5230
end
5331
end

Diff for: spec/controllers/spree/base_controller_spec.rb

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
def index; authorize!(:read, :something); end
99
end
1010

11-
before do
12-
stub_spree_preferences(Spree::Config, redirect_back_on_unauthorized: true)
13-
end
14-
1511
context "when user is logged in" do
1612
before { sign_in(create(:user)) }
1713

0 commit comments

Comments
 (0)