tap/app/models/ability.rb

28 lines
556 B
Ruby
Raw Normal View History

2014-12-09 19:44:58 +01:00
class Ability
include CanCan::Ability
def initialize(user)
2015-09-14 20:26:16 +02:00
return unless user
2015-10-07 15:52:05 +02:00
can :read, Barcode
2015-09-20 21:21:18 +02:00
2014-12-09 19:44:58 +01:00
if user.admin?
can :manage, :all
2015-01-06 20:18:01 +01:00
elsif user.koelkast?
2015-09-21 08:23:43 +02:00
can :manage, Order do |order|
!order.try(:user).try(:private)
end
2015-09-18 15:46:11 +02:00
can :quickpay, User
2015-09-14 20:26:16 +02:00
else
2014-12-09 19:44:58 +01:00
can :read, :all
can :manage, User, id: user.id
2015-09-14 20:26:16 +02:00
can :create, Order do |order|
order.try(:user) == user
end
2015-10-26 18:57:59 +01:00
can :destroy, Order do |order|
order.try(:user) == user && order.deletable
2015-09-14 20:26:16 +02:00
end
2014-12-09 19:44:58 +01:00
end
end
end