Class: Kaui::Ability

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

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Ability

Returns a new instance of Ability.



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

def initialize(user)
  # user is a Kaui::User object (from Devise)
  user.permissions.each do |permission|
    # permission is something like invoice:item_adjust or payment:refund
    # We rely on a naming convention where the left part refers to a Kaui model
    model, action = permission.split(':')
    if model == '*' and action == '*'
      # All permissions!
      can :manage, :all
    elsif model == '*' and action != '*'
      # TODO
    elsif action == '*'
      can :all, ('Kaui::' + model.capitalize).constantize rescue nil
    else
      can action.to_sym, ('Kaui::' + model.capitalize).constantize rescue nil
    end
  end
rescue KillBillClient::API::Unauthorized => e
end