Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rob-mcgrail/fecf0f9a5016c99bae37b1645cb7fe83 to your computer and use it in GitHub Desktop.
Save rob-mcgrail/fecf0f9a5016c99bae37b1645cb7fe83 to your computer and use it in GitHub Desktop.
authorize via relate? with a reference to the related class.
module JSONAPI
module Authorization
class DefaultPunditAuthorizer
def create_resource(source_class, related_records)
::Pundit.authorize(user, source_class, 'create?')
related_records.each do |record|
user.define_singleton_method(:source_class) do
source_class
end
::Pundit.authorize(user, record, 'relate?')
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment