-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start out by reusing the solidus_backend authentication method in the…
… new admin
- Loading branch information
Showing
2 changed files
with
38 additions
and
5 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
admin/app/controllers/solidus_admin/auth_adapters/backend.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusAdmin::AuthAdapters::Backend | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
delegate :admin_logout_path, to: :spree | ||
helper_method :admin_logout_path | ||
end | ||
|
||
private | ||
|
||
def authenticate_solidus_backend_user! | ||
if respond_to?(:model_class, true) && model_class | ||
record = model_class | ||
else | ||
record = controller_name.to_sym | ||
end | ||
authorize! :admin, record | ||
authorize! action_name.to_sym, record | ||
rescue CanCan::AccessDenied | ||
instance_exec(&Spree::Admin::BaseController.unauthorized_redirect) | ||
end | ||
|
||
# Needs to be overriden so that we use Spree's Ability rather than anyone else's. | ||
def current_ability | ||
@current_ability ||= Spree::Ability.new(spree_current_user) | ||
end | ||
|
||
def store_location | ||
Spree::UserLastUrlStorer.new(self).store_location | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters