Class: Ability

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

Instance Method Summary collapse

Constructor Details

#initialize(u) ⇒ Ability

Returns a new instance of Ability.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/forge/app/models/ability.rb', line 4

def initialize(u)
  if u.is_super_admin?
    can :manage, :all
    can :publish, :all
    can :assign_roles, User
  elsif u.is_admin?
    can :manage, :all
    can :publish, :all
    can :assign_roles, User
    can(:destroy, Page) { |page| page.key.blank? }
  elsif u.is_contributor?
    can([:update, :edit], User) { |user| user == u }
    can :read, :all
    can :create, Page
    can([:update, :destroy, :edit], Page) do |item|
      u.id == item.creator_id
    end
    can(:destroy, Page) { |page| page.key.blank? }
  else
    can :read, :all
  end
end