我希望管理员用户无法创建具有超级管理员角色的用户,但仍然可以创建其他管理员和常规用户。我该如何做到这一点?这是我的Ability.rb:
class Ability
include CanCan::Ability
def initialize(user)
if user.super_admin?
can :manage, :all
elsif user.admin?
can :manage, [Article, Comment]
can [:destroy, :update], User, :role_id => 2 # If Admin
can [:destroy, :update], User, :role_id => 3 # If User
can :read, User
can :create, User
elsif user.user_regular?
#cannot :read, ActiveAdmin::Page, :name => "Dashboard"
#can :manage, :all
end
end
end
答案 0 :(得分:0)
在cannot
块admin
中使用cannot :creat, User, :role_id => 1 # let 1 is super admin role id
。您可以获得有关合并能力at here