Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pundit error: not allowed to index? this Class #2389

Open
burmashave opened this issue Jun 1, 2023 · 1 comment
Open

Pundit error: not allowed to index? this Class #2389

burmashave opened this issue Jun 1, 2023 · 1 comment

Comments

@burmashave
Copy link

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?

@nickcharlton
Copy link
Member

Hello! I wonder if this is caused by the change which was eventually fixed in #2383.

Could you try pulling from main and seeing if that resolves the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants