2015-05-05 03:10:25 +02:00
|
|
|
class EventPolicy < ApplicationPolicy
|
|
|
|
class Scope < Scope
|
|
|
|
def resolve
|
|
|
|
if user.nil? or (user and !user.is_admin?)
|
2016-06-24 18:26:11 +02:00
|
|
|
scope.includes(:event_image, :event_files, :availability, :categories)
|
2015-05-05 03:10:25 +02:00
|
|
|
.where('availabilities.start_at >= ?', Time.now)
|
|
|
|
.order('availabilities.start_at ASC')
|
|
|
|
.references(:availabilities)
|
|
|
|
else
|
2016-06-24 18:26:11 +02:00
|
|
|
scope.includes(:event_image, :event_files, :availability, :categories)
|
2015-05-05 03:10:25 +02:00
|
|
|
.order('availabilities.start_at DESC')
|
|
|
|
.references(:availabilities)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create?
|
|
|
|
user.is_admin?
|
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
|
|
|
create?
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy?
|
|
|
|
create?
|
|
|
|
end
|
|
|
|
end
|