Skip to content

Commit

Permalink
Show a deprecation message for legacy routes
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Dec 23, 2022
1 parent bd2e854 commit bf56a64
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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
42 changes: 22 additions & 20 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/controllers/frontend/spree/user_passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/controllers/frontend/spree/user_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/controllers/frontend/spree/users_controller.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit bf56a64

Please sign in to comment.