Class: ReservationSummaryPolicy
Overview
Policy for Partners::ReservationSummary objects that provides exact same logic as ReservationPolicy but uses summary data to avoid N+1 queries. All time-dependent calculations are done in real-time.
Defined Under Namespace
Classes: Scope
Instance Attribute Summary
#object, #user
Instance Method Summary
collapse
#initialize, #scope
Instance Method Details
#be_reminded? ⇒ Boolean
Check if booking reminder can be sent
94
95
96
97
98
99
100
101
|
# File 'app/policies/reservation_summary_policy.rb', line 94
def be_reminded?
if owner_scope? && now < object.reservation_time && object.active && !object.no_show && !object.arrived && !object.delivery?
!BookingReminder::ManualQueue.new(object.reservation_id).has_reminded?
else
false
end
end
|
#can_give_review? ⇒ Boolean
26
27
28
29
|
# File 'app/policies/reservation_summary_policy.rb', line 26
def can_give_review?
false
end
|
#cancel? ⇒ Boolean
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/policies/reservation_summary_policy.rb', line 51
def cancel?
return false unless object
return false unless my_reservation?
reservation_time_limit = if owner_scope?
object.reservation_time + 30.minutes
else
object.reservation_time
end
now <= reservation_time_limit
end
|
#create? ⇒ Boolean
31
32
33
|
# File 'app/policies/reservation_summary_policy.rb', line 31
def create?
true
end
|
#destroy? ⇒ Boolean
47
48
49
|
# File 'app/policies/reservation_summary_policy.rb', line 47
def destroy?
false
end
|
#edit? ⇒ Boolean
43
44
45
|
# File 'app/policies/reservation_summary_policy.rb', line 43
def edit?
update?
end
|
#editable? ⇒ Boolean
Core editable logic - always calculated in real-time
64
65
66
|
# File 'app/policies/reservation_summary_policy.rb', line 64
def editable?
now <= object.reservation_time.twenty_four_hours_later && !object.adjusted? && !cancelled_by_user?
end
|
#index? ⇒ Boolean
13
14
15
|
# File 'app/policies/reservation_summary_policy.rb', line 13
def index?
true
end
|
#mark_arrived?(by_owner: false) ⇒ Boolean
Check if reservation can be marked as arrived
72
73
74
75
76
77
78
79
80
|
# File 'app/policies/reservation_summary_policy.rb', line 72
def mark_arrived?(by_owner: false)
if by_owner
editable? && !object.arrived
else
editable? && !object.arrived
end
end
|
#mark_no_show?(by_owner: false) ⇒ Boolean
Check if reservation can be marked as no show
86
87
88
89
|
# File 'app/policies/reservation_summary_policy.rb', line 86
def mark_no_show?(by_owner: false)
editable? && !object.no_show
end
|
#new? ⇒ Boolean
35
36
37
|
# File 'app/policies/reservation_summary_policy.rb', line 35
def new?
create?
end
|
#owner_has_sent_custom_sms? ⇒ Boolean
Custom SMS permission - uses real-time past? calculation
104
105
106
107
108
109
110
111
112
113
|
# File 'app/policies/reservation_summary_policy.rb', line 104
def owner_has_sent_custom_sms?
return true unless owner_scope?
if object.past?
true
else
object.custom_sms_sent_by_owner == true
end
end
|
#show? ⇒ Boolean
21
22
23
24
|
# File 'app/policies/reservation_summary_policy.rb', line 21
def show?
(user&.kinda_like_owner? && user.restaurant_ids.include?(object.restaurant_id)) ||
(user&.user? && (object.user_id == user.id))
end
|
#update? ⇒ Boolean
39
40
41
|
# File 'app/policies/reservation_summary_policy.rb', line 39
def update?
show? && editable?
end
|
#valid_user? ⇒ Boolean
17
18
19
|
# File 'app/policies/reservation_summary_policy.rb', line 17
def valid_user?
object.user_id.present?
end
|