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.

Fix getting current user (#11820)

Weronika Witekdd503abc55c3
diff --git a/api/app/controllers/spree/api/v2/base_controller.rb b/api/app/controllers/spree/api/v2/base_controller.rb
index 21cafcae51..02760585d3 100644
--- a/api/app/controllers/spree/api/v2/base_controller.rb
+++ b/api/app/controllers/spree/api/v2/base_controller.rb
@@ -82,6 +82,8 @@ module Spree
@spree_current_user ||= doorkeeper_token.resource_owner
end
+ alias try_spree_current_user spree_current_user # for compatibility with spree_legacy_frontend
+
def spree_authorize!(action, subject, *args)
authorize!(action, subject, *args)
end
diff --git a/core/lib/spree/core/controller_helpers/locale.rb b/core/lib/spree/core/controller_helpers/locale.rb
index 3cc7facfa7..5273a303a2 100644
--- a/core/lib/spree/core/controller_helpers/locale.rb
+++ b/core/lib/spree/core/controller_helpers/locale.rb
@@ -23,7 +23,7 @@ module Spree
def current_locale
@current_locale ||= if user_locale?
- spree_current_user.selected_locale
+ try_spree_current_user.selected_locale
elsif params_locale?
params[:locale]
elsif config_locale?
@@ -42,7 +42,7 @@ module Spree
end
def user_locale?
- Spree::Config.use_user_locale && spree_current_user && supported_locale?(spree_current_user.selected_locale)
+ Spree::Config.use_user_locale && try_spree_current_user && supported_locale?(try_spree_current_user.selected_locale)
end
def supported_locales
diff --git a/core/spec/lib/spree/core/controller_helpers/auth_spec.rb b/core/spec/lib/spree/core/controller_helpers/auth_spec.rb
index 19f873a0b3..ad0655013e 100644
--- a/core/spec/lib/spree/core/controller_helpers/auth_spec.rb
+++ b/core/spec/lib/spree/core/controller_helpers/auth_spec.rb
@@ -25,10 +25,6 @@ describe Spree::Core::ControllerHelpers::Auth, type: :controller do
end
end
- let(:user) { build(:user) }
-
- before { allow(controller).to receive(:spree_current_user).and_return(user) }
-
it 'redirects to session url' do
session[:spree_user_return_to] = '/redirect'
get :index
@@ -53,10 +49,6 @@ describe Spree::Core::ControllerHelpers::Auth, type: :controller do
end
end
- let(:user) { build(:user) }
-
- before { allow(controller).to receive(:spree_current_user).and_return(user) }
-
it 'sends cookie header' do
get :index
expect(response.cookies['token']).not_to be_nil
@@ -96,13 +88,9 @@ describe Spree::Core::ControllerHelpers::Auth, type: :controller do
end
end
- let(:user) { build(:user, selected_locale: 'pl') }
-
- before { allow(controller).to receive(:spree_current_user).and_return(user) }
-
context 'when logged in' do
before do
- allow(controller).to receive_messages(try_spree_current_user: double('User', id: 1, last_incomplete_spree_order: nil))
+ allow(controller).to receive_messages(try_spree_current_user: double('User', id: 1, last_incomplete_spree_order: nil, selected_locale: nil))
end
it 'redirects forbidden path' do