2014-12-09 19:44:58 +01:00
|
|
|
class Ability
|
|
|
|
include CanCan::Ability
|
|
|
|
|
|
|
|
def initialize(user)
|
|
|
|
user ||= User.new # guest user (not logged in)
|
2015-08-31 14:33:15 +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?
|
|
|
|
can :manage, Order
|
2015-02-10 07:15:25 +01:00
|
|
|
elsif user[:id]
|
2014-12-09 19:44:58 +01:00
|
|
|
can :read, :all
|
2015-08-31 14:33:15 +02:00
|
|
|
can :manage, User, id: user.id
|
2015-08-31 15:10:13 +02:00
|
|
|
can :manage, Order do |order|
|
|
|
|
order.try(:user) == user
|
|
|
|
end
|
2014-12-09 19:44:58 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|