Simplify ability
This commit is contained in:
parent
7cc2ec6a20
commit
b7ac8c32f7
1 changed files with 25 additions and 17 deletions
|
@ -4,24 +4,32 @@ class Ability
|
|||
def initialize(user)
|
||||
return unless user
|
||||
|
||||
can :read, Barcode
|
||||
initialize_admin if user.admin?
|
||||
initialize_koelkast if user.koelkast?
|
||||
initialize_user
|
||||
|
||||
if user.admin?
|
||||
can :manage, :all
|
||||
elsif user.koelkast?
|
||||
can :manage, Order do |order|
|
||||
!order.try(:user).try(:private)
|
||||
end
|
||||
can :quickpay, User
|
||||
else
|
||||
can :read, :all
|
||||
can :manage, User, id: user.id
|
||||
can :create, Order do |order|
|
||||
order.try(:user) == user
|
||||
end
|
||||
can :destroy, Order do |order|
|
||||
order.try(:user) == user && order.deletable
|
||||
end
|
||||
can :read, Barcode
|
||||
end
|
||||
|
||||
def initialize_admin
|
||||
can :manage, :all
|
||||
end
|
||||
|
||||
def initialize_koelkast
|
||||
can :manage, Order do |order|
|
||||
!order.try(:user).try(:private)
|
||||
end
|
||||
can :quickpay, User
|
||||
end
|
||||
|
||||
def initialize_user
|
||||
can :read, :all
|
||||
can :manage, User, id: user.id
|
||||
can :create, Order do |order|
|
||||
order.try(:user) == user
|
||||
end
|
||||
can :destroy, Order do |order|
|
||||
order.try(:user) == user && order.deletable
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue