From eac5f296e392d7e6a2c8cf02c07c70e2b717759b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 12 Jan 2023 13:47:39 +0100 Subject: [PATCH 1/2] Improve deprecation messages for the Auth module --- core/lib/spree/core/controller_helpers/auth.rb | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/core/lib/spree/core/controller_helpers/auth.rb b/core/lib/spree/core/controller_helpers/auth.rb index 35afa14534d..924341cdb0c 100644 --- a/core/lib/spree/core/controller_helpers/auth.rb +++ b/core/lib/spree/core/controller_helpers/auth.rb @@ -37,12 +37,6 @@ def current_ability end def redirect_back_or_default(default) - Spree::Deprecation.warn <<~MSG - 'Please use #stored_spree_user_location_or when using solidus_auth_devise. - Otherwise, please utilize #redirect_back provided in Rails 5+ or - #redirect_back_or_to in Rails 7+ instead' - MSG - redirect_to(session["spree_user_return_to"] || default) session["spree_user_return_to"] = nil end @@ -57,11 +51,6 @@ def set_guest_token end def store_location - Spree::Deprecation.warn <<~MSG - store_location is being deprecated in solidus 4.0 - without replacement - MSG - Spree::UserLastUrlStorer.new(self).store_location end @@ -83,7 +72,11 @@ def try_spree_current_user end end - deprecate try_spree_current_user: :spree_current_user, deprecator: Spree::Deprecation + deprecate \ + try_spree_current_user: :spree_current_user, + redirect_back_or_default: 'Please use `redirect_to stored_spree_user_location_or(...)` when using solidus_auth_devise.', + store_location: 'Please use `store_location_for(:spree_user, request.fullpath)` when using solidus_auth_devise.', + deprecator: Spree::Deprecation end end end From 0e41bb418a60f1213eec5b83f02cb13703b0bf9e Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 12 Jan 2023 13:48:21 +0100 Subject: [PATCH 2/2] Use a guard check instead of wrapping the whole method body Appeasing Rubocop in the process. --- core/lib/spree/core/controller_helpers/auth.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/lib/spree/core/controller_helpers/auth.rb b/core/lib/spree/core/controller_helpers/auth.rb index 924341cdb0c..9854f97bc65 100644 --- a/core/lib/spree/core/controller_helpers/auth.rb +++ b/core/lib/spree/core/controller_helpers/auth.rb @@ -42,12 +42,12 @@ def redirect_back_or_default(default) end def set_guest_token - unless cookies.signed[:guest_token].present? - cookies.permanent.signed[:guest_token] = Spree::Config[:guest_token_cookie_options].merge( - value: SecureRandom.urlsafe_base64(nil, false), - httponly: true - ) - end + return if cookies.signed[:guest_token].present? + + cookies.permanent.signed[:guest_token] = Spree::Config[:guest_token_cookie_options].merge( + value: SecureRandom.urlsafe_base64(nil, false), + httponly: true + ) end def store_location