Simplify ability

This commit is contained in:
benji 2015-10-29 14:09:52 +01:00
parent 7cc2ec6a20
commit b7ac8c32f7

View file

@ -4,16 +4,25 @@ class Ability
def initialize(user) def initialize(user)
return unless user return unless user
can :read, Barcode initialize_admin if user.admin?
initialize_koelkast if user.koelkast?
initialize_user
if user.admin? can :read, Barcode
end
def initialize_admin
can :manage, :all can :manage, :all
elsif user.koelkast? end
def initialize_koelkast
can :manage, Order do |order| can :manage, Order do |order|
!order.try(:user).try(:private) !order.try(:user).try(:private)
end end
can :quickpay, User can :quickpay, User
else end
def initialize_user
can :read, :all can :read, :all
can :manage, User, id: user.id can :manage, User, id: user.id
can :create, Order do |order| can :create, Order do |order|
@ -24,4 +33,3 @@ class Ability
end end
end end
end end
end