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
|
2020-09-29 08:40:07 +02:00
|
|
|
if user.nil? || (user && !user.admin? && !user.manager?)
|
2023-01-19 17:41:21 +01:00
|
|
|
scope.includes(:event_image, :event_files, :availability, :category, :event_price_categories, :age_range, :events_event_themes,
|
|
|
|
:event_themes)
|
2023-02-14 13:10:58 +01:00
|
|
|
.where('availabilities.start_at >= ?', Time.current)
|
2023-01-19 17:41:21 +01:00
|
|
|
.where(deleted_at: nil)
|
2015-05-05 03:10:25 +02:00
|
|
|
.order('availabilities.start_at ASC')
|
|
|
|
.references(:availabilities)
|
|
|
|
else
|
2023-01-19 17:41:21 +01:00
|
|
|
scope.includes(:event_image, :event_files, :availability, :category, :event_price_categories, :age_range, :events_event_themes,
|
|
|
|
:event_themes)
|
|
|
|
.where(deleted_at: nil)
|
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
|