Class: LoyalPassport::Ability

Inherits:
Object
  • Object
show all
Defined in:
app/models/loyal_passport/ability.rb

Instance Method Summary collapse

Constructor Details

#initialize(ability, current_user) ⇒ Ability

Returns a new instance of Ability.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/loyal_passport/ability.rb', line 3

def initialize ability, current_user
  #            屏蔽用户
  ability.can [:review], [::User] do |user|
    # 不是超级用户          当前用户有相应权限                        被管理的用户有相应的权限
    user.not_super_admin? && current_user.homework?(:review, :user) && user.unhomework?(:review, :user)
  end

  ability.can [:destroy, :block], [::User] do |user|
    ability.can?(:review, user)
  end

  # 能更新用户的信息
  ability.can [:update], [::User] do |user|
    (current_user.id == user.id) || ability.can?(:review, user)
  end

end