@@ -21,9 +21,7 @@ class BaseController < ActionController::Base
2121 class_attribute :admin_metadata_attributes
2222 self . admin_metadata_attributes = [ { admin_metadata : { } } ]
2323
24- attr_accessor :current_api_user
25-
26- before_action :load_user
24+ before_action :deprecated_load_user
2725 before_action :authorize_for_order , if : proc { order_token . present? }
2826 before_action :authenticate_user
2927 # This is deprecated and will be removed in Spree 5.0
@@ -36,7 +34,7 @@ class BaseController < ActionController::Base
3634 rescue_from StateMachines ::InvalidTransition , with : :invalid_transition
3735
3836 helper Spree ::Api ::ApiHelpers
39- helper_method :current_user_roles
37+ helper_method :current_user_roles , :current_api_user
4038
4139 private
4240
@@ -63,12 +61,12 @@ def permitted_user_attributes
6361 can? ( :admin , Spree . user_class ) ? super + admin_metadata_attributes : super
6462 end
6563
66- def load_user
67- @current_api_user ||= Spree . user_class . find_by ( spree_api_key : api_key . to_s )
64+ def current_api_user
65+ @_current_api_user ||= Spree . user_class . find_by ( spree_api_key : api_key . to_s )
6866 end
6967
7068 def authenticate_user
71- unless @ current_api_user
69+ unless current_api_user
7270 if requires_authentication? && api_key . blank? && order_token . blank?
7371 render "spree/api/errors/must_specify_api_key" , status : :unauthorized
7472 elsif order_token . blank? && ( requires_authentication? || api_key . present? )
@@ -85,9 +83,17 @@ def load_deprecated_user_roles
8583 end
8684 end
8785
86+ def deprecated_load_user
87+ @current_api_user = if Rails . version < Gem ::Version . new ( "7.2.0" )
88+ ActiveSupport ::Deprecation ::DeprecatedInstanceVariableProxy . new ( self , :current_api_user , :@current_api_user , Spree . deprecator )
89+ else
90+ ActiveSupport ::Deprecation ::DeprecatedInstanceVariableProxy . new ( self , :current_api_user , :@current_api_user , deprecator : Spree . deprecator )
91+ end
92+ end
93+
8894 def current_user_roles
89- @_current_user_roles ||= if @ current_api_user
90- @ current_api_user. spree_roles . pluck ( :name )
95+ @_current_user_roles ||= if current_api_user
96+ current_api_user . spree_roles . pluck ( :name )
9197 else
9298 [ ]
9399 end
0 commit comments