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

32 lines
810 B
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
2019-09-25 16:37:42 +02:00
if user.nil? || (user && !user.admin?)
scope.includes(:event_image, :event_files, :availability, :category)
.where('availabilities.start_at >= ?', DateTime.current)
2015-05-05 03:10:25 +02:00
.order('availabilities.start_at ASC')
.references(:availabilities)
else
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