简体   繁体   English

没有:manage:all,RailsAdmin + Devise + CanCanCan角色将不起作用

[英]RailsAdmin + Devise + CanCanCan role not works without :manage :all

I apologize in advance for my English and knowledge of ruby :) I making admin panel with RailsAdmin , authentication with Devise , authorisation with CanCanCan , so, I have three boolean fields in User: 我事先为我的英语和红宝石知识表示歉意:)我使用RailsAdmin创建管理面板,使用Devise进行身份验证,使用CanCanCan进行授权,因此,我在User中具有三个布尔字段:

add_column :users, :superadmin_role, :boolean, default: false
enter code hereadd_column :users, :manager_role, :boolean, default:

So, in ability.rb i have this: 因此,在capability.rb中,我有这个:

class Ability

  include CanCan::Ability

  def initialize(user)
    user ||= User.new # guest user (not logged in)
    can :access, :dashboard    # allow access to dashboard
    can :access, :rails_admin  # access Rails Admin for Admin-users

    if user.superadmin_role?
      can :manage, :all
    end # role works correct

    if user.manager_role?
      can :read, :all   
    end #role works incorrect

  end
end

SUPERADMIN_ROLE works correct and allow to enter to RailsAdmin and etc., but MANAGER_ROLE is doesn't work - when user try enter in Dashboard, there is an Access Denied error message is showing: SUPERADMIN_ROLE可以正常工作,并允许进入RailsAdmin等,但是MANAGER_ROLE不起作用-当用户尝试在仪表板中输入时,显示“拒绝访问”错误消息:

仪表板访问被拒绝错误

How to provide access for manager_role to dashboard and RailsAdmin interface - have broke the whole brain. 如何为manager_role提供对仪表板和RailsAdmin界面的访问权限-真是无所适从。

I will be glad to any help (ready code, links @where to read and etc) and constructive criticism 我将很高兴获得任何帮助(准备好的代码,指向@where的链接等)和建设性的批评

cancancan2 needs a different adapter for RailsAdmin. cancancan2需要用于RailsAdmin的其他适配器。 Please look at this issue: https://github.com/CanCanCommunity/cancancan/issues/413 and this issue: https://github.com/sferik/rails_admin/issues/2901 . 请查看此问题: https : //github.com/CanCanCommunity/cancancan/issues/413和此问题: https : //github.com/sferik/rails_admin/issues/2901

On the first link you will find the code needed to create an adapter. 在第一个链接上,您将找到创建适配器所需的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM