2020-04-27 12:12:29 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Check the access policies for API::SlotsController
|
2016-03-23 18:39:41 +01:00
|
|
|
class SlotPolicy < ApplicationPolicy
|
|
|
|
def update?
|
|
|
|
# check that the update is allowed and the prevention delay has not expired
|
2020-04-27 12:12:29 +02:00
|
|
|
delay = Setting.find_by(name: 'booking_move_delay').value.to_i
|
|
|
|
enabled = (Setting.find_by(name: 'booking_move_enable').value == 'true')
|
2016-03-23 18:39:41 +01:00
|
|
|
|
|
|
|
# these condition does not apply to admins
|
2020-04-27 12:12:29 +02:00
|
|
|
user.admin? || user.manager? ||
|
|
|
|
(record.reservation.user == user && enabled && ((record.start_at - DateTime.current).to_i / 3600 >= delay))
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def cancel?
|
2020-04-27 12:12:29 +02:00
|
|
|
user.admin? || user.manager? || record.reservation.user == user
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
end
|