1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/policies/event_policy.rb

36 lines
1.1 KiB
Ruby
Raw Normal View History

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
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)
.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