Replies: 2 comments
-
Hey! Thanks! I've been using Grape for a while, but I think looking at our GraphQL integration might be useful. Especially this file: https://github.com/palkan/action_policy-graphql/blob/master/lib/action_policy/graphql/behaviour.rb Note that we override |
Beta Was this translation helpful? Give feedback.
-
I don't love this, but this was the only way I was able to get it to work. module ActionPolicy
module Grape
module Helpers
extend ActiveSupport::Concern
included do
include ActionPolicy::Behaviour
include ActionPolicy::Behaviours::ThreadMemoized
include ActionPolicy::Behaviours::Memoized
include ActionPolicy::Behaviours::Namespaced
authorize :user, through: :current_user
end
end
end
end
module Grape
class Endpoint
include ActionPolicy::Grape::Helpers
end
end From the Grape documentation,
Keeping authorization context as state on this class should work, since we'll always have access to that context within routes and before/after hooks. The problem is that it doesn't give the flexibility to override contexts per endpoint, if that's desired. |
Beta Was this translation helpful? Give feedback.
-
Hi @palkan,
thanks a lot for your awesome work on the gem and also with the community here! I'm about to integrate the gem into a Grape based API and was wondering if there was some integration work on non-rails app done, which doesn't force me to use something like the service object pattern - as shown in the documentation?
At the moment I'm working on something like this:
which could be used in a before_action of grape:
This follows the documented example and is working in general. But I was looking for something like Pundit is offering:
When I try to build something like it with action_policy:
I get the error message
undefined method authorization_targets for #<Class:
. I was trying to overwrite theauthorization_context
but this feels like a bad idea.So I was wondering if there is already some experience with integrating action_policy into Grape and if not, which of the approaches about would be "the preferred way"?
Thanks a lot for your feedback and opinion!
Beta Was this translation helpful? Give feedback.
All reactions