您可以使用Devise和Active Admin禁用Pundit吗? [英] Can you disable Pundit with Devise and Active Admin?

查看:185
本文介绍了您可以使用Devise和Active Admin禁用Pundit吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经遵循了:



如何让Active Admin登录后与Pundit合作



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



我现在不需要授权 - 用于认证的设计会做。我可以只需关闭主动管理员权限?



更新 p>

这是超级猴子补丁:

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

但我不认为它是理想的。

解决方案

您可以尝试设置授权适配器



设置自己的AuthorizationAdapter很容易!以下示例显示如何将授权适配器类设置为Active Admin:

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

def授权?(action,subject = nil)
false
end

end

然后

  config.authorization_adapter = NotAdminAuthorization

其他您可以定义命名空间切换

  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

然后像这样

  ActiveAdmin.register Post,命名空间::my_user 
/ pre>

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.

解决方案

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

这篇关于您可以使用Devise和Active Admin禁用Pundit吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆