Sha256: b787662e251cb4100033e64a3e122e8cf4e511ace88c684a9f5a17a0b8f7c8a8

Contents?: true

Size: 874 Bytes

Versions: 7

Compression:

Stored size: 874 Bytes

Contents

# frozen_string_literal: true

require 'pundit'

module Ditty
  module Helpers
    module Pundit
      include ::Pundit

      def authorize(record, query)
        query = :"#{query}?" unless query[-1] == '?'
        super
      end

      def permitted_attributes(record, action)
        param_key = PolicyFinder.new(record).param_key
        policy = policy(record)
        method_name = if policy.respond_to?("permitted_attributes_for_#{action}")
                        "permitted_attributes_for_#{action}"
                      else
                        'permitted_attributes'
                      end

        policy_fields = policy.public_send(method_name)
        request.params.fetch(param_key, {}).select do |key, _value|
          policy_fields.include? key.to_sym
        end
      end

      def pundit_user
        current_user
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ditty-0.8.0 lib/ditty/helpers/pundit.rb
ditty-0.7.2 lib/ditty/helpers/pundit.rb
ditty-0.7.1 lib/ditty/helpers/pundit.rb
ditty-0.7.0 lib/ditty/helpers/pundit.rb
ditty-0.7.0.pre.rc1 lib/ditty/helpers/pundit.rb
ditty-0.6.0 lib/ditty/helpers/pundit.rb
ditty-0.4.1 lib/ditty/helpers/pundit.rb