2019-09-25 16:37:42 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Check the access policies for API::EventsController
|
2015-05-05 03:10:25 +02:00
|
|
|
class EventPolicy < ApplicationPolicy
|
2019-09-25 16:37:42 +02:00
|
|
|
# Defines the scope of the events index, depending on the role of the current user
|
2015-05-05 03:10:25 +02:00
|
|
|
class Scope < Scope
|
|
|
|
def resolve
|
2019-09-25 16:37:42 +02:00
|
|
|
if user.nil? || (user && !user.admin?)
|
2016-07-25 16:16:25 +02:00
|
|
|
scope.includes(:event_image, :event_files, :availability, :category)
|
2019-12-02 11:57:25 +01:00
|
|
|
.where('availabilities.start_at >= ?', DateTime.current)
|
2015-05-05 03:10:25 +02:00
|
|
|
.order('availabilities.start_at ASC')
|
|
|
|
.references(:availabilities)
|
|
|
|
else
|
2016-07-25 16:16:25 +02:00
|
|
|
scope.includes(:event_image, :event_files, :availability, :category)
|
2015-05-05 03:10:25 +02:00
|
|
|
.references(:availabilities)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create?
|
2020-04-28 12:48:03 +02:00
|
|
|
user.admin? || user.manager?
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
|
|
|
create?
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy?
|
|
|
|
create?
|
|
|
|
end
|
|
|
|
end
|