Class: Ability
- Inherits:
-
Object
- Object
- Ability
- Includes:
- CanCan::Ability
- Defined in:
- app/models/ability.rb
Instance Method Summary collapse
-
#initialize(user) ⇒ Ability
constructor
A new instance of Ability.
Constructor Details
#initialize(user) ⇒ 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 26 27 28 29 30 31 |
# File 'app/models/ability.rb', line 4 def initialize(user) if user.root can :manage, :all else user.user_roles.each do |ur| model = ur.role.modelize if model can :read, model if ur.priveleged?(:read) can [:new, :create], model if ur.priveleged?(:create) can [:edit, :update], model if ur.priveleged?(:edit) can :destroy, model if ur.priveleged?(:destroy) end end Terminal::ORDERS.each do |order| can order, Terminal if user.priveleged?(:terminals, order) end end cannot :destroy, User do |x| x == user end cannot :destroy, ProviderReceiptTemplate do |x| x.system? end end |