policy scope has_many relationships

This commit is contained in:
Devin Howard 2016-10-25 10:35:19 +08:00
parent 4b2ecc3fac
commit 4f312d7c21

View file

@ -32,9 +32,11 @@ module Api
if attr.to_s.pluralize == attr.to_s if attr.to_s.pluralize == attr.to_s
attribute("#{attr.to_s.singularize}_ids".to_sym, attribute("#{attr.to_s.singularize}_ids".to_sym,
opts.merge(unless: -> { embeds.include?(key) })) do opts.merge(unless: -> { embeds.include?(key) })) do
object.send(attr).map(&:id) Pundit.policy_scope(scope[:current_user], object.send(:topics)).map(&:id)
end
has_many(attr, opts.merge(if: -> { embeds.include?(key) })) do
Pundit.policy_scope(scope[:current_user], object.send(:topics))
end end
has_many(attr, opts.merge(if: -> { embeds.include?(key) }))
else else
id_opts = opts.merge(key: "#{key}_id") id_opts = opts.merge(key: "#{key}_id")
attribute("#{attr}_id".to_sym, attribute("#{attr}_id".to_sym,