Skip to content

Commit

Permalink
Make Unauthorized Redirect patch autoloadable
Browse files Browse the repository at this point in the history
  • Loading branch information
mamhoff committed Nov 21, 2024
1 parent 460808d commit c9473a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
4 changes: 0 additions & 4 deletions lib/alchemy/solidus/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 0 additions & 9 deletions lib/alchemy/solidus/spree_admin_unauthorized_redirect.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c9473a5

Please sign in to comment.