mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-04 15:24:23 +01:00
29 lines
652 B
Ruby
29 lines
652 B
Ruby
class EventPolicy < ApplicationPolicy
|
|
class Scope < Scope
|
|
def resolve
|
|
if user.nil? or (user and !user.is_admin?)
|
|
scope.includes(:event_image, :event_files, :availability)
|
|
.where('availabilities.start_at >= ?', Time.now)
|
|
.order('availabilities.start_at ASC')
|
|
.references(:availabilities)
|
|
else
|
|
scope.includes(:event_image, :event_files, :availability)
|
|
.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
|