diff --git a/lib/alchemy/solidus/engine.rb b/lib/alchemy/solidus/engine.rb index ab3de68..b898f28 100644 --- a/lib/alchemy/solidus/engine.rb +++ b/lib/alchemy/solidus/engine.rb @@ -25,10 +25,6 @@ class Engine < ::Rails::Engine Alchemy.register_ability ::Spree::Ability ::Spree::Ability.register_ability ::Alchemy::Permissions - if Alchemy.user_class_name == "::Alchemy::User" - require "alchemy/solidus/spree_admin_unauthorized_redirect" - end - if SolidusSupport.frontend_available? # Allows to render Alchemy content within Solidus' controller views diff --git a/lib/alchemy/solidus/spree_admin_unauthorized_redirect.rb b/lib/alchemy/solidus/spree_admin_unauthorized_redirect.rb deleted file mode 100644 index e680f4c..0000000 --- a/lib/alchemy/solidus/spree_admin_unauthorized_redirect.rb +++ /dev/null @@ -1,9 +0,0 @@ -Spree::Admin::BaseController.unauthorized_redirect = -> do - if spree_current_user - flash[:error] = I18n.t('spree.authorization_failure') - redirect_to spree.root_path - else - store_location - redirect_to Alchemy.login_path - end -end diff --git a/lib/controllers/backend/alchemy/solidus/spree_admin_base_controller_decorator.rb b/lib/controllers/backend/alchemy/solidus/spree_admin_base_controller_decorator.rb new file mode 100644 index 0000000..8cff8b4 --- /dev/null +++ b/lib/controllers/backend/alchemy/solidus/spree_admin_base_controller_decorator.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Alchemy + module Solidus + module SpreeAdminBaseControllerDecorator + def self.prepended(base) + if Alchemy.user_class_name == "::Alchemy::User" + base.unauthorized_redirect = -> do + if spree_current_user + flash[:error] = I18n.t('spree.authorization_failure') + redirect_to spree.root_path + else + store_location + redirect_to Alchemy.login_path + end + end + end + end + + if defined?(::Spree::Admin::BaseController) + ::Spree::Admin::BaseController.prepend self + end + end + end +end