Can you disable Pundit with Devise and Active Admin?

百般思念 提交于 2019-12-12 02:28:00

问题


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.


回答1:


config.authentication_method = false  
config.current_user_method   = false

In your config/initializers/active_admin.rb




回答2:


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


来源:https://stackoverflow.com/questions/34649465/can-you-disable-pundit-with-devise-and-active-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!