Class: Ability

Inherits:
Object show all
Includes:
CanCan::Ability
Defined in:
lib/generators/ab_admin/install/templates/models/ability.rb

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Ability


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/generators/ab_admin/install/templates/models/ability.rb', line 4

def initialize(user)
  alias_action :destroy, to: :delete

  @user = user

  if @user
    send(@user.user_role_type.code)
  else
    guest
  end
end

Instance Method Details

#adminObject


35
36
37
38
39
# File 'lib/generators/ab_admin/install/templates/models/ability.rb', line 35

def admin
  can :manage, :all

  cannot :destroy, User, id: @user.id
end

#defaultObject


19
20
21
# File 'lib/generators/ab_admin/install/templates/models/ability.rb', line 19

def default
  guest
end

#guestObject


16
17
# File 'lib/generators/ab_admin/install/templates/models/ability.rb', line 16

def guest
end

#moderatorObject


27
28
29
30
31
32
33
# File 'lib/generators/ab_admin/install/templates/models/ability.rb', line 27

def moderator
  default
  can :manage, Dashboard
  can [:read, :create], AdminComment
  can :destroy, AdminComment, user_id: @user.id
  cannot :destroy, User, id: @user.id
end

#redactorObject


23
24
25
# File 'lib/generators/ab_admin/install/templates/models/ability.rb', line 23

def redactor
  default
end