Class: Ability

Inherits:
Object
  • Object
show all
Includes:
CanCan::Ability
Defined in:
app/models/ability.rb

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Ability

Returns a new instance of Ability.



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
39
# File 'app/models/ability.rb', line 6

def initialize(user)
  if user

    # Owners can do everything

    if user.owner?
      can :manage, :all
      return
    end

    # Admins can create teams

    if user.admin?
      can [:read, :create], Team
    end

    # If you're logged in, you can see teams

    can :read, :teams

    # Users get abilities based on their role
    # in any teams they are members of

    user.roles.each do |role|
      Houston.config.configure_team_abilities(self, role)
    end
  end

  if Houston.config.defines_abilities?
    Houston.config.configure_abilities(self, user)
  else
    default_abilities_for(user)
  end
end

Instance Method Details

#default_abilities_for(user) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'app/models/ability.rb', line 43

def default_abilities_for(user)
  return unless user

  # If you're logged in, you can see everything
  can :read, :all

  # If you're logged in, you can update yourself
  can :update, user
end