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

16 lines
544 B
Ruby
Raw Normal View History

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
delay = Setting.find_by( name: 'booking_move_delay').value.to_i
enabled = (Setting.find_by( name: 'booking_move_enable').value == 'true')
# these condition does not apply to admins
user.admin? or
(record.reservation.user == user and enabled and ((record.start_at - DateTime.current).to_i / 3600 >= delay))
2016-03-23 18:39:41 +01:00
end
def cancel?
user.admin? or record.reservation.user == user
2016-03-23 18:39:41 +01:00
end
end