Skip to content

Make hook available to authorize resource? #62

@barelyknown

Description

@barelyknown

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions