Skip to content

Commit af6b6db

Browse files
committed
Start out by reusing the solidus_backend authentication method in the new admin
1 parent 61b39e6 commit af6b6db

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
module SolidusAdmin::AuthAdapters::Backend
4+
extend ActiveSupport::Concern
5+
6+
included do
7+
delegate :admin_logout_path, to: :spree
8+
helper_method :admin_logout_path
9+
end
10+
11+
private
12+
13+
def authenticate_solidus_backend_user!
14+
if respond_to?(:model_class, true) && model_class
15+
record = model_class
16+
else
17+
record = controller_name.to_sym
18+
end
19+
authorize! :admin, record
20+
authorize! action_name.to_sym, record
21+
rescue CanCan::AccessDenied
22+
instance_exec(&Spree::Admin::BaseController.unauthorized_redirect)
23+
end
24+
25+
# Needs to be overriden so that we use Spree's Ability rather than anyone else's.
26+
def current_ability
27+
@current_ability ||= Spree::Ability.new(spree_current_user)
28+
end
29+
30+
def store_location
31+
Spree::UserLastUrlStorer.new(self).store_location
32+
end
33+
end

admin/lib/solidus_admin/configuration.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@ def main_nav
8484

8585
# The method used to authenticate the user in the admin interface, it's expected to redirect the user to the login method
8686
# in case the authentication fails.
87-
preference :authentication_method, :string, default: nil
87+
preference :authentication_method, :string, default: :authenticate_solidus_backend_user!
8888

8989
# The method used to retrieve the current user in the admin interface.
90-
preference :current_user_method, :string, default: nil
90+
preference :current_user_method, :string, default: :spree_current_user
9191

9292
# The path used to logout the user in the admin interface.
93-
preference :logout_link_path, :string, default: nil
93+
preference :logout_link_path, :string, default: :admin_logout_path
9494

9595
# The HTTP method used to logout the user in the admin interface.
96-
preference :logout_link_method, :string, default: nil
96+
preference :logout_link_method, :string, default: :delete
9797

9898
# A module that will be included in the BaseController to add authentication support
9999
# methods, can be `nil` if no module is needed.
100-
preference :authentication_adapter, :string, default: nil
100+
preference :authentication_adapter, :string, default: 'SolidusAdmin::AuthAdapters::Backend'
101101
end
102102
end
103103

0 commit comments

Comments
 (0)