Sha256: 8fa7eeaf7f7c3b338b636f1650c3c7c41036794e2f0fec852ddd540de0c6f56a
Contents?: true
Size: 830 Bytes
Versions: 3
Compression:
Stored size: 830 Bytes
Contents
module Kaui class Ability include CanCan::Ability 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 end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
kaui-0.7.2 | app/models/kaui/ability.rb |
kaui-0.7.1 | app/models/kaui/ability.rb |
kaui-0.7.0 | app/models/kaui/ability.rb |