Add ability for controller to use CanCan

This commit is contained in:
Gaetan Craig-Riou
2024-01-09 14:44:12 +11:00
parent e11d1582f2
commit 626e903ab9

View File

@@ -8,6 +8,7 @@ module DfcProvider
protect_from_forgery with: :null_session
rescue_from ActiveRecord::RecordNotFound, with: :not_found
rescue_from CanCan::AccessDenied, with: :unauthorized
before_action :check_authorization
@@ -16,7 +17,7 @@ module DfcProvider
private
def check_authorization
head :unauthorized if current_user.nil?
unauthorized if current_user.nil?
end
def check_enterprise
@@ -50,5 +51,13 @@ module DfcProvider
def not_found
head :not_found
end
def unauthorized
head :unauthorized
end
def current_ability
@current_ability ||= Spree::Ability.new(current_user)
end
end
end