Can you disable Pundit with Devise and Active Admi

2019-09-10 00:26发布

I have an existing Rails app that has Devise / Pundit running on the User model.

I have followed:

How to get Active Admin to work with Pundit after login

https://gist.github.com/tomchentw/8579571

I don't need authorization right now - Devise for authentication will do. Can I just "turn off" Pundit for Active Admin?

UPDATE

This is super monkey patch:

after_action :verify_policy_scoped, only: [:index] if controller_path.split('/').first == "admin"

It works but I don't think it's ideal.

2条回答
The star\"
2楼-- · 2019-09-10 00:34
config.authentication_method = false  
config.current_user_method   = false

In your config/initializers/active_admin.rb

查看更多
孤傲高冷的网名
3楼-- · 2019-09-10 00:51

You can try to set up authorization adapter

Setting up your own AuthorizationAdapter is easy! The following example shows how to set up and tie your authorization adapter class to Active Admin:

# app/models/only_authors_authorization.rb
class NotAdminAuthorization < ActiveAdmin::AuthorizationAdapter

  def authorized?(action, subject = nil)
   false
  end

end

then

config.authorization_adapter = "NotAdminAuthorization"

and other you can define the namespace toggle

ActiveAdmin.setup do |config|
  config.namespace :admin do |ns|
    ns.authorization_adapter = "NotAdminAuthorization"
  end
  config.namespace :my_user do |ns|
    ns.authorization_adapter =  ActiveAdmin::PunditAdapter
  end
end

Then like this to

ActiveAdmin.register Post, namespace: :my_user
查看更多
登录 后发表回答