-
-
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.
Merge pull request #5390 from solidusio/elia/admin/authorization
[admin] Separate authorization from authentication
- Loading branch information
Showing
9 changed files
with
67 additions
and
44 deletions.
There are no files selected for viewing
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
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
37 changes: 0 additions & 37 deletions
37
admin/app/controllers/solidus_admin/auth_adapters/backend.rb
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
admin/app/controllers/solidus_admin/authentication_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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusAdmin::AuthenticationAdapters::Backend | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
delegate :admin_logout_path, to: :spree | ||
helper_method :admin_logout_path | ||
end | ||
|
||
private | ||
|
||
def authenticate_solidus_backend_user! | ||
return if spree_current_user | ||
|
||
instance_exec(&Spree::Admin::BaseController.unauthorized_redirect) | ||
end | ||
|
||
def store_location | ||
Spree::UserLastUrlStorer.new(self).store_location | ||
end | ||
|
||
def spree_current_user | ||
defined?(super) ? super : nil | ||
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
2 changes: 1 addition & 1 deletion
2
.../solidus_admin/controller_helpers/auth.rb → ...dmin/controller_helpers/authentication.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
29 changes: 29 additions & 0 deletions
29
admin/app/controllers/solidus_admin/controller_helpers/authorization.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,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusAdmin::ControllerHelpers::Authorization | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
before_action :authorize_solidus_admin_user! | ||
end | ||
|
||
private | ||
|
||
def current_ability | ||
@current_ability ||= Spree::Ability.new(current_solidus_admin_user) | ||
end | ||
|
||
def authorize_solidus_admin_user! | ||
subject = authorization_subject | ||
|
||
authorize! :admin, subject | ||
authorize! action_name, subject | ||
end | ||
|
||
def authorization_subject | ||
"Spree::#{controller_name.classify}".constantize | ||
rescue NameError | ||
raise NotImplementedError, "Couldn't infer the model class from the controller name, " \ | ||
"please implement `#{self.class}#authorization_subject`." | ||
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
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