@@ -26,7 +26,8 @@ class BaseController < ActionController::Base
2626 before_action :load_user
2727 before_action :authorize_for_order , if : proc { order_token . present? }
2828 before_action :authenticate_user
29- before_action :load_user_roles
29+ # This is deprecated and will be removed in Spree 5.0
30+ before_action :load_deprecated_user_roles
3031
3132 rescue_from ActionController ::ParameterMissing , with : :parameter_missing_error
3233 rescue_from ActiveRecord ::RecordNotFound , with : :not_found
@@ -35,6 +36,7 @@ class BaseController < ActionController::Base
3536 rescue_from StateMachines ::InvalidTransition , with : :invalid_transition
3637
3738 helper Spree ::Api ::ApiHelpers
39+ helper_method :current_user_roles
3840
3941 private
4042
@@ -75,8 +77,16 @@ def authenticate_user
7577 end
7678 end
7779
78- def load_user_roles
79- @current_user_roles = if @current_api_user
80+ def load_deprecated_user_roles
81+ @current_user_roles = if Rails . version < Gem ::Version . new ( "7.2.0" )
82+ ActiveSupport ::Deprecation ::DeprecatedInstanceVariableProxy . new ( self , :current_user_roles , :@current_user_roles , Spree . deprecator )
83+ else
84+ ActiveSupport ::Deprecation ::DeprecatedInstanceVariableProxy . new ( self , :current_user_roles , :@current_user_roles , deprecator : Spree . deprecator )
85+ end
86+ end
87+
88+ def current_user_roles
89+ @_current_user_roles ||= if @current_api_user
8090 @current_api_user . spree_roles . pluck ( :name )
8191 else
8292 [ ]
0 commit comments