togglepro / pundit-resources

Integrate Pundit policies with jsonapi-resources
MIT License
46 stars 39 forks source link

Support for permitted_attributes #20

Open spiderbites opened 8 years ago

spiderbites commented 8 years ago

Hey, thanks for the gem, I've been using it on a project and am really enjoying the design.

Wondering if you have any ideas about implementing pundit's permitted_attributes feature (https://github.com/elabs/pundit#strong-parameters) via a pundit-resources defined policy.

NuckChorris commented 7 years ago

If I'm not mistaken, this would be as simple as something like this:

module PunditResource
  def self.updatable_fields(context)
    policy.permitted_attributes
  end

  def self.creatable_fields(context)
    policy.permitted_attributess
  end
end

JSONAPI::Resources already provides hooks for this exact purpose. I'll send a PR in a couple weeks if nobody beats me to the punch