Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

When forbidden error happens in admin try to redirect user back to th… (#13226)

Damian Legawiec87e422961a77
diff --git a/admin/app/controllers/spree/admin/base_controller.rb b/admin/app/controllers/spree/admin/base_controller.rb
index fcc7b754bc..50588e7f76 100644
--- a/admin/app/controllers/spree/admin/base_controller.rb
+++ b/admin/app/controllers/spree/admin/base_controller.rb
@@ -34,7 +34,7 @@ module Spree
def redirect_unauthorized_access
if try_spree_current_user
flash[:error] = Spree.t(:authorization_failure)
- redirect_to spree.admin_forbidden_path, allow_other_host: true
+ redirect_back(fallback_location: spree.admin_forbidden_path)
else
store_location
try_to_redirect_to_login_path
diff --git a/admin/spec/controllers/spree/admin/base_controller_spec.rb b/admin/spec/controllers/spree/admin/base_controller_spec.rb
index 2af196d9b2..727c50cfba 100644
--- a/admin/spec/controllers/spree/admin/base_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/base_controller_spec.rb
@@ -26,9 +26,17 @@ describe Spree::Admin::BaseController, type: :controller do
persisted?: true, selected_locale: nil))
end
- it 'redirects forbidden path' do
+ it 'redirects back to referer when present and shows a flash error' do
+ request.env['HTTP_REFERER'] = '/admin/products'
+ get :index
+ expect(response).to redirect_to('/admin/products')
+ expect(flash[:error]).to eq(Spree.t(:authorization_failure))
+ end
+
+ it 'redirects to forbidden path as fallback when no referer and shows a flash error' do
get :index
expect(response).to redirect_to('/admin/forbidden')
+ expect(flash[:error]).to eq(Spree.t(:authorization_failure))
end
end