tab/app/models/user_ability.rb

16 lines
407 B
Ruby
Raw Normal View History

2015-09-11 13:16:53 +02:00
class UserAbility
2015-09-08 17:18:38 +02:00
include CanCan::Ability
def initialize(user)
2015-09-09 16:56:55 +02:00
return unless user
2015-09-08 17:18:38 +02:00
2015-09-09 16:56:55 +02:00
can :manage, :all if user.penning?
2017-01-09 15:46:43 +01:00
can :read, user, id: user.id
can :manage, Request, creditor_id: user.id
2017-01-09 16:22:58 +01:00
can :manage, Notification, user_id: user.id
can :create, Transaction do |t|
2018-03-13 15:27:34 +01:00
t.debtor == user && (t.debtor.balance - t.amount >= 0 || t.debtor.debt_allowed?)
end
2015-09-08 17:18:38 +02:00
end
end