Skip to content

Instantly share code, notes, and snippets.

@denisoster
Created October 7, 2020 09:00
Show Gist options
  • Save denisoster/3ce9ea5b5be71a81f1ef96a9e1d4b18e to your computer and use it in GitHub Desktop.
Save denisoster/3ce9ea5b5be71a81f1ef96a9e1d4b18e to your computer and use it in GitHub Desktop.
active_admin/pundit_adapter.rb
def scope_collection(collection, action = Auth::READ)
# # scoping is appliable only to read/index action
# # which means there is no way how to scope other actions
# Pundit.policy_scope!(user, namespace(collection))
# rescue Pundit::NotDefinedError => e
# if default_policy_class && default_policy_class.const_defined?(:Scope)
# default_policy_class::Scope.new(user, collection).resolve
# else
# raise e
# end
#
policy_scope = Pundit.policy_scope(user, namespace(collection))
return policy_scope if policy_scope.present?
return default_policy_class::Scope.new(user, collection).resolve if default_policy_class && default_policy_class.const_defined?(:Scope)
raise NotDefinedError, "unable to find scope `#{Pundit::PolicyFinder.new(namespace(collection)).send(:find, namespace(collection))}::Scope` for `#{namespace(collection).inspect}`"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment