Module: AuthcanEasyroller::Ability

Defined in:
lib/extensions/cancan_ability.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/extensions/cancan_ability.rb', line 40

def self.included(base)
  base.send :include, CanCan::Ability

  base.class_eval {
    def initialize(current_user)
      ae_ability_defaults(current_user)
    end
  }
end

Instance Method Details

#ae_ability_defaults(current_user) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/extensions/cancan_ability.rb', line 4

def ae_ability_defaults(current_user)
  can :read, :all
  can :manage, UserSession

  if current_user
    # Abilities for someone with an account (does not necessarily have a "user" role)
    can [:edit], User do |user|
      user == current_user
    end

    # User role abilities
    if current_user.is_user?
    end


    # Moderator role abilities
    if current_user.is_moderator?
    end


    # Admin role abilities
    if current_user.is_admin?
      can :manage, :all
    end


    # Developer role abilities
    if current_user.is_developer?
      can :manage, :all
    end
  else
    can :create, User
  end

end