I'd like to authorize resources using an approach like the convention followed by pundit. Here's what a typical controller action would look like (from the pundit documentation).
def update
@post = Post.find(params[:id])
authorize @post
if @post.update(post_params)
redirect_to @post
else
render :edit
end
end
First you get the resource, then authorize it (which raises an exception if it fails), and then proceed.
For the index action, pundit provides the concept of a "scope" which gets the set of resources that the user has access to.
def index
@posts = policy_scope(Post)
end
Anyhow, I don't see a straight forward way to hook into the controller methods since so much happens in the process_request_operations method. I think that it would be great for it to yield the resources so that they could be authorized in the middle of that method's execution.
What do you think?
I'd like to authorize resources using an approach like the convention followed by
pundit. Here's what a typical controller action would look like (from thepunditdocumentation).First you get the resource, then authorize it (which raises an exception if it fails), and then proceed.
For the index action,
punditprovides the concept of a "scope" which gets the set of resources that the user has access to.Anyhow, I don't see a straight forward way to hook into the controller methods since so much happens in the
process_request_operationsmethod. I think that it would be great for it to yield the resources so that they could be authorized in the middle of that method's execution.What do you think?