Class: Virgo::Ability

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

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Ability

Returns a new instance of Ability.


7
8
9
10
11
# File 'app/models/virgo/ability.rb', line 7

def initialize(user)
  @user = user || User.new # for guest

  send(@user.role) if @user.role.present?
end

Instance Method Details

#adminObject


51
52
53
# File 'app/models/virgo/ability.rb', line 51

def admin
  can :manage, :all
end

#anonymousObject


13
14
15
16
17
# File 'app/models/virgo/ability.rb', line 13

def anonymous
  can :read, Post do |post|
    post.published? && post.live
  end
end

#contributorObject


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/virgo/ability.rb', line 31

def contributor
  can :manage, Virgo::Post do |post|
    post.author == @user
  end

  can :manage, Virgo::Slideshow do |slideshow|
    slideshow.author == @user
  end

  can :manage, Virgo::Slide do |slide|
    can?(:manage, slide.slideshow)
  end

  can :read, Virgo::Post

  cannot :manage, Virgo::User
  cannot :manage, Virgo::Column
  cannot :manage, Virgo::Site
end

#editorObject


23
24
25
26
27
28
29
# File 'app/models/virgo/ability.rb', line 23

def editor
  can :manage, :all
  can :manage, Virgo::User do |u|
    u == @user
  end
  cannot :index, Virgo::User
end

#normalObject


19
20
21
# File 'app/models/virgo/ability.rb', line 19

def normal
  anonymous
end

#superuserObject


55
56
57
# File 'app/models/virgo/ability.rb', line 55

def superuser
  can :manage, :all
end