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

19 lines
612 B
Ruby
Raw Normal View History

# 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-05-13 15:02:03 +02:00
delay = Setting.get('booking_move_delay').to_i
2020-05-25 16:47:06 +02:00
enabled = Setting.get('booking_move_enable')
2016-03-23 18:39:41 +01:00
# these condition does not apply to admins
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?
user.admin? || user.manager? || record.reservation.user == user
2016-03-23 18:39:41 +01:00
end
end