Sha256: e834d7e3152b77807518b7e25298abec2e742919a49bc624bca0421c8ebff8f2

Contents?: true

Size: 826 Bytes

Versions: 2

Compression:

Stored size: 826 Bytes

Contents

module Pundit
  module Logger
    # If Pundit authorization fails, the policy name and associated
    # information is logged to the configured logger.
    #
    # Intended for mixing into Rails controllers
    #
    # Functionality controlled by
    # Pundit::Logger.log_unauthorized_policies; disable by setting
    # that to false.
    module LogUnauthorizedPolicies

      extend ActiveSupport::Concern

      included do
        around_action :log_unauthorized_policies,
          if: -> { Pundit::Logger.log_unauthorized_policies? }
      end

      private

      def log_unauthorized_policies
        yield
      rescue Pundit::NotAuthorizedError => e
        Pundit::Logger.log "Authorization Failed for "\
                           "#{e.policy.class.name}: #{e.message}"
        raise e
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pundit_logger-0.1.1 lib/pundit_logger/log_unauthorized_policies.rb
pundit_logger-0.1.0 lib/pundit_logger/log_unauthorized_policies.rb