diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bf5aaba1..c30b3d35 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -21,7 +21,6 @@ Gemspec/OrderedDependencies: Layout/ArgumentAlignment: Exclude: - 'app/models/spree/user.rb' - - 'lib/spree/authentication_helpers.rb' - 'spec/controllers/spree/user_sessions_controller_spec.rb' - 'spec/features/sign_out_spec.rb' @@ -351,7 +350,6 @@ Style/GuardClause: - 'db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb' - 'db/migrate/20190125170630_add_reset_password_token_index_to_spree_users.rb' - 'db/migrate/20200417153503_add_unconfirmed_email_to_spree_users.rb' - - 'lib/spree/authentication_helpers.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). diff --git a/app/patches/controllers/solidus_auth_devise/application_controller_patch.rb b/app/patches/controllers/solidus_auth_devise/application_controller_patch.rb new file mode 100644 index 00000000..07b0bc40 --- /dev/null +++ b/app/patches/controllers/solidus_auth_devise/application_controller_patch.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module SolidusAuthDevise + module ApplicationControllerPatch + def self.prepended(base) + return unless base.respond_to?(:helper_method) + + base.send(:helper_method, :spree_current_user) + + return unless SolidusSupport.frontend_available? + + base.send(:helper_method, :spree_login_path) + base.send(:helper_method, :spree_signup_path) + base.send(:helper_method, :spree_logout_path) + end + + def spree_current_user + current_spree_user + end + + if SolidusSupport.frontend_available? + delegate :login_path, :signup_path, :logout_path, + to: :spree, + prefix: :spree + end + + ApplicationController.prepend self + end +end diff --git a/lib/decorators/backend/controllers/spree/admin/orders/customer_details_controller_decorator.rb b/lib/decorators/backend/controllers/spree/admin/orders/customer_details_controller_decorator.rb deleted file mode 100644 index 1628f53b..00000000 --- a/lib/decorators/backend/controllers/spree/admin/orders/customer_details_controller_decorator.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Spree::Admin::Orders::CustomerDetailsControllerDecorator - def self.prepended(base) - base.before_action :check_authorization - end - - private - - def check_authorization - load_order - session[:access_token] ||= params[:token] - - resource = @order - action = params[:action].to_sym - action = :edit if action == :show # show route renders :edit for this controller - - authorize! action, resource, session[:access_token] - end - - Spree::Admin::Orders::CustomerDetailsController.prepend self -end diff --git a/lib/decorators/backend/controllers/spree/admin/base_controller_decorator.rb b/lib/patches/backend/controllers/solidus_auth_devise/admin/base_controller_patch.rb similarity index 85% rename from lib/decorators/backend/controllers/spree/admin/base_controller_decorator.rb rename to lib/patches/backend/controllers/solidus_auth_devise/admin/base_controller_patch.rb index f0017543..2bf97c3e 100644 --- a/lib/decorators/backend/controllers/spree/admin/base_controller_decorator.rb +++ b/lib/patches/backend/controllers/solidus_auth_devise/admin/base_controller_patch.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -module Spree +module SolidusAuthDevise module Admin - module BaseControllerDecorator + module BaseControllerPatch protected def model_class diff --git a/lib/patches/backend/controllers/solidus_auth_devise/admin/orders/customer_details_controller_patch.rb b/lib/patches/backend/controllers/solidus_auth_devise/admin/orders/customer_details_controller_patch.rb new file mode 100644 index 00000000..62b0ca75 --- /dev/null +++ b/lib/patches/backend/controllers/solidus_auth_devise/admin/orders/customer_details_controller_patch.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module SolidusAuthDevise + module Admin + module Orders + module CustomerDetailsControllerPatch + def self.prepended(base) + base.before_action :check_authorization + end + + private + + def check_authorization + load_order + session[:access_token] ||= params[:token] + + resource = @order + action = params[:action].to_sym + action = :edit if action == :show # show route renders :edit for this controller + + authorize! action, resource, session[:access_token] + end + + Spree::Admin::Orders::CustomerDetailsController.prepend self + end + end + end +end diff --git a/lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb b/lib/patches/frontend/controllers/solidus_auth_devise/checkout_controller_patch.rb similarity index 97% rename from lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb rename to lib/patches/frontend/controllers/solidus_auth_devise/checkout_controller_patch.rb index a0f55a19..ca28a1f9 100644 --- a/lib/decorators/frontend/controllers/spree/checkout_controller_decorator.rb +++ b/lib/patches/frontend/controllers/solidus_auth_devise/checkout_controller_patch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -module Spree - module CheckoutControllerDecorator +module SolidusAuthDevise + module CheckoutControllerPatch def self.prepended(base) base.before_action :check_registration, except: [:registration, :update_registration] base.before_action :check_authorization diff --git a/lib/solidus_auth_devise.rb b/lib/solidus_auth_devise.rb index f38cd2f4..56f69a53 100644 --- a/lib/solidus_auth_devise.rb +++ b/lib/solidus_auth_devise.rb @@ -10,5 +10,3 @@ require 'solidus_auth_devise/configuration' require 'solidus_auth_devise/version' require 'solidus_auth_devise/engine' - -require 'spree/authentication_helpers' diff --git a/lib/spree/auth/engine.rb b/lib/spree/auth/engine.rb index f0e98489..3d4db4a3 100644 --- a/lib/spree/auth/engine.rb +++ b/lib/spree/auth/engine.rb @@ -24,8 +24,6 @@ class Engine < Rails::Engine config.to_prepare do Spree::Auth::Engine.prepare_backend if SolidusSupport.backend_available? Spree::Auth::Engine.prepare_frontend if SolidusSupport.frontend_available? - - ApplicationController.include Spree::AuthenticationHelpers end def self.redirect_back_on_unauthorized? diff --git a/lib/spree/authentication_helpers.rb b/lib/spree/authentication_helpers.rb deleted file mode 100644 index d62a20c4..00000000 --- a/lib/spree/authentication_helpers.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module Spree - module AuthenticationHelpers - def self.included(receiver) - if receiver.send(:respond_to?, :helper_method) - receiver.send(:helper_method, :spree_current_user) - - if SolidusSupport.frontend_available? - receiver.send(:helper_method, :spree_login_path) - receiver.send(:helper_method, :spree_signup_path) - receiver.send(:helper_method, :spree_logout_path) - end - end - end - - def spree_current_user - current_spree_user - end - - if SolidusSupport.frontend_available? - delegate :login_path, :signup_path, :logout_path, - to: :spree, - prefix: :spree - end - end -end diff --git a/solidus_auth_devise.gemspec b/solidus_auth_devise.gemspec index 17a4032a..9cdb8912 100644 --- a/solidus_auth_devise.gemspec +++ b/solidus_auth_devise.gemspec @@ -32,7 +32,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'devise', '~> 4.1' spec.add_dependency 'devise-encryptable', '0.2.0' spec.add_dependency 'solidus_core', ['>= 3', '< 5'] - spec.add_dependency 'solidus_support', '~> 0.5' + spec.add_dependency 'solidus_support', '~> 0.11' spec.add_development_dependency 'solidus_backend' spec.add_development_dependency 'solidus_frontend'