thoughtbot / thoughtbot/administrate

Pundit error: not allowed to index? this Class

Open
#2,389 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
6k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I just started using administrate and encountered a problem when integrating with Pundit.

When I include Administrate::Punditize in the Admin::ApplicationController, I get a Pundit::NotAuthorizedError at my /admin route, with error: not allowed to index? this Class.

The action I'm rooting to is:

namespace :admin do
  resources :venues
  resources :users
  
  root to: "venues#index"
end

The Venues controller has:

  def index
    @venues = policy_scope(Venue)
  end

And the policy has:

class VenuePolicy < ApplicationPolicy
  class Scope < Scope
    def resolve
      scope.visible_to(user)
    end
  end

visible_to is an included module scope:

class_methods do
  def visible_to(user)
    user&.admin? ? all : published
  end
end

The policy works outside of administrate, so I'm not sure what I'm doing wrong here. Any ideas?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Pundit::NotAuthorizedError at /admin with Administrate::Punditize included in Admin::ApplicationController. Trace the admin root through VenuesController#index, policy_scope(Venue), and VenuePolicy::Scope#resolve, comparing it with the working behavior outside Administrate. Done means the integration's authorization behavior is understood and the reported /admin error has a confirmed resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
authorization, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.