From bf56a644f975728afa9d584929f1897ae777f3fa Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 23 Dec 2022 13:53:49 +0100 Subject: [PATCH] Show a deprecation message for legacy routes --- .../controller_helpers/deprecated_routes.rb | 36 ++++++++++++++++ config/routes.rb | 42 ++++++++++--------- .../spree/user_confirmations_controller.rb | 2 + .../spree/user_passwords_controller.rb | 2 + .../spree/user_registrations_controller.rb | 2 + .../spree/user_sessions_controller.rb | 2 + .../frontend/spree/users_controller.rb | 2 + 7 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 app/controllers/solidus_auth_devise/controller_helpers/deprecated_routes.rb diff --git a/app/controllers/solidus_auth_devise/controller_helpers/deprecated_routes.rb b/app/controllers/solidus_auth_devise/controller_helpers/deprecated_routes.rb new file mode 100644 index 00000000..f086064b --- /dev/null +++ b/app/controllers/solidus_auth_devise/controller_helpers/deprecated_routes.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module SolidusAuthDevise + module ControllerHelpers + module DeprecatedRoutes + extend ActiveSupport::Concern + + included do + before_action :deprecates_solidus_auth_devise_routes + end + + private + + def deprecates_solidus_auth_devise_routes + if params[:deprecated_route] + Spree::Deprecation.warn( + <<~TEXT + This route is deprecated: #{request.fullpath.inspect}. + It will be removed in solidus_auth_devise v3. + If you want to continue using this route please define it in your application code: + + Spree::Core::Engine.routes.draw do + devise_scope :spree_user do + #{request.method.downcase} #{request.fullpath.inspect}, to: #{controller_path}##{action_name}, ... + end + end + + Please check your application for places in which this route was generated. + + TEXT + ) + end + end + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 74580ec8..713b54dd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,28 +35,30 @@ # # These are deprecated but we still want to support the incoming routes, in order to give existing stores an upgrade path. # Will be removed at the next major release of solidus_auth_devise. - get '/user/spree_user/password/edit' => 'user_passwords#edit', as: :deprecated_edit_spree_user_password - get '/password/change' => 'user_passwords#edit', as: :edit_spree_user_password - get '/user/spree_user/password/new' => 'user_passwords#new', as: :deprecated_new_spree_user_password - get '/password/recover' => 'user_passwords#new', as: :new_spree_user_password - match '/user/spree_user/password' => 'user_passwords#update', via: [:patch, :put], as: :deprecated_spree_user_password - put '/password/change' => 'user_passwords#update', as: :spree_user_password - post '/user/spree_user/password' => 'user_passwords#create', as: nil + with_options deprecated_route: true do + get '/user/spree_user/password/edit' => 'user_passwords#edit', as: :deprecated_edit_spree_user_password + get '/password/change' => 'user_passwords#edit', as: :edit_spree_user_password + get '/user/spree_user/password/new' => 'user_passwords#new', as: :deprecated_new_spree_user_password + get '/password/recover' => 'user_passwords#new', as: :new_spree_user_password + match '/user/spree_user/password' => 'user_passwords#update', via: [:patch, :put], as: :deprecated_spree_user_password + put '/password/change' => 'user_passwords#update', as: :spree_user_password + post '/user/spree_user/password' => 'user_passwords#create', as: nil - get '/login' => 'user_sessions#new', as: :new_spree_user_session - get '/user/spree_user/sign_in' => 'user_sessions#new', as: :deprecated_new_spree_user_session - match '/user/spree_user/logout' => 'user_sessions#destroy', via: Devise.sign_out_via, as: :deprecated_destroy_spree_user_session - match '/logout' => 'user_sessions#destroy', via: Devise.sign_out_via, as: :destroy_spree_user_session - post '/user/spree_user/sign_in' => 'user_sessions#create', as: :deprecated_spree_user_session - post '/login' => 'user_sessions#create', as: :spree_user_session + get '/login' => 'user_sessions#new', as: :new_spree_user_session + get '/user/spree_user/sign_in' => 'user_sessions#new', as: :deprecated_new_spree_user_session + match '/user/spree_user/logout' => 'user_sessions#destroy', via: Devise.sign_out_via, as: :deprecated_destroy_spree_user_session + match '/logout' => 'user_sessions#destroy', via: Devise.sign_out_via, as: :destroy_spree_user_session + post '/user/spree_user/sign_in' => 'user_sessions#create', as: :deprecated_spree_user_session + post '/login' => 'user_sessions#create', as: :spree_user_session - get '/user/spree_user/sign_up' => 'user_registrations#new', as: :deprecated_new_spree_user_registration - get '/signup' => 'user_registrations#new', as: :new_spree_user_registration - post '/user/spree_user' => 'user_registrations#create', as: nil - get '/user/spree_user/cancel' => 'user_registrations#cancel', as: :cancel_spree_user_registration - get '/user/spree_user/edit' => 'user_registrations#edit', as: :edit_spree_user_registration - delete '/user/spree_user' => 'user_registrations#destroy', as: nil - match '/user/spree_user' => 'user_registrations#update', as: :spree_user_registration, via: [:patch, :put] + get '/user/spree_user/sign_up' => 'user_registrations#new', as: :deprecated_new_spree_user_registration + get '/signup' => 'user_registrations#new', as: :new_spree_user_registration + post '/user/spree_user' => 'user_registrations#create', as: nil + get '/user/spree_user/cancel' => 'user_registrations#cancel', as: :cancel_spree_user_registration + get '/user/spree_user/edit' => 'user_registrations#edit', as: :edit_spree_user_registration + delete '/user/spree_user' => 'user_registrations#destroy', as: nil + match '/user/spree_user' => 'user_registrations#update', as: :spree_user_registration, via: [:patch, :put] + end end get '/checkout/registration', to: 'checkout#registration', as: :checkout_registration diff --git a/lib/controllers/frontend/spree/user_confirmations_controller.rb b/lib/controllers/frontend/spree/user_confirmations_controller.rb index 41bace4a..ed5ce299 100644 --- a/lib/controllers/frontend/spree/user_confirmations_controller.rb +++ b/lib/controllers/frontend/spree/user_confirmations_controller.rb @@ -8,6 +8,8 @@ class Spree::UserConfirmationsController < Devise::ConfirmationsController include Spree::Core::ControllerHelpers::Order include Spree::Core::ControllerHelpers::Store + include SolidusAuthDevise::ControllerHelpers::DeprecatedRoutes + protected def after_confirmation_path_for(resource_name, resource) diff --git a/lib/controllers/frontend/spree/user_passwords_controller.rb b/lib/controllers/frontend/spree/user_passwords_controller.rb index 80d24d53..5ceaaa31 100644 --- a/lib/controllers/frontend/spree/user_passwords_controller.rb +++ b/lib/controllers/frontend/spree/user_passwords_controller.rb @@ -8,6 +8,8 @@ class Spree::UserPasswordsController < Devise::PasswordsController include Spree::Core::ControllerHelpers::Order include Spree::Core::ControllerHelpers::Store + include SolidusAuthDevise::ControllerHelpers::DeprecatedRoutes + # Overridden due to bug in Devise. # respond_with resource, location: new_session_path(resource_name) # is generating bad url /session/new.user diff --git a/lib/controllers/frontend/spree/user_registrations_controller.rb b/lib/controllers/frontend/spree/user_registrations_controller.rb index b1b42195..fc7c643b 100644 --- a/lib/controllers/frontend/spree/user_registrations_controller.rb +++ b/lib/controllers/frontend/spree/user_registrations_controller.rb @@ -8,6 +8,8 @@ class Spree::UserRegistrationsController < Devise::RegistrationsController include Spree::Core::ControllerHelpers::Order include Spree::Core::ControllerHelpers::Store + include SolidusAuthDevise::ControllerHelpers::DeprecatedRoutes + before_action :check_permissions, only: [:edit, :update] skip_before_action :require_no_authentication diff --git a/lib/controllers/frontend/spree/user_sessions_controller.rb b/lib/controllers/frontend/spree/user_sessions_controller.rb index dfa67d99..c4f35b46 100644 --- a/lib/controllers/frontend/spree/user_sessions_controller.rb +++ b/lib/controllers/frontend/spree/user_sessions_controller.rb @@ -8,6 +8,8 @@ class Spree::UserSessionsController < Devise::SessionsController include Spree::Core::ControllerHelpers::Order include Spree::Core::ControllerHelpers::Store + include SolidusAuthDevise::ControllerHelpers::DeprecatedRoutes + # This is included in ControllerHelpers::Order. We just want to call # it after someone has successfully logged in. after_action :set_current_order, only: :create diff --git a/lib/controllers/frontend/spree/users_controller.rb b/lib/controllers/frontend/spree/users_controller.rb index b6f31b45..ee6cf7a0 100644 --- a/lib/controllers/frontend/spree/users_controller.rb +++ b/lib/controllers/frontend/spree/users_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Spree::UsersController < Spree::StoreController + include SolidusAuthDevise::ControllerHelpers::DeprecatedRoutes + skip_before_action :set_current_order, only: :show, raise: false prepend_before_action :authorize_actions, only: :new