Class: ReservationSummaryPolicy

Inherits:
ApplicationPolicy show all
Defined in:
app/policies/reservation_summary_policy.rb

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.

Examples:

Usage

ReservationSummaryPolicy.new(staff, reservation_summary).editable?

Defined Under Namespace

Classes: Scope

Instance Attribute Summary

Attributes inherited from ApplicationPolicy

#object, #user

Instance Method Summary collapse

Methods inherited from ApplicationPolicy

#initialize, #scope

Constructor Details

This class inherits a constructor from ApplicationPolicy

Instance Method Details

#be_reminded?Boolean

Check if booking reminder can be sent

Returns:

  • (Boolean)

    true if reminder can be sent



94
95
96
97
98
99
100
101
# File 'app/policies/reservation_summary_policy.rb', line 94

def be_reminded?
  # Check if reservation is eligible for reminders and not already 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

Returns:

  • (Boolean)


26
27
28
29
# File 'app/policies/reservation_summary_policy.rb', line 26

def can_give_review?
  # Not used in serializers, return false to avoid complex logic
  false
end

#cancel?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


31
32
33
# File 'app/policies/reservation_summary_policy.rb', line 31

def create?
  true
end

#destroy?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/policies/reservation_summary_policy.rb', line 47

def destroy?
  false
end

#edit?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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

Returns:

  • (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

Parameters:

  • by_owner (Boolean) (defaults to: false)

    whether the action is performed by owner

Returns:

  • (Boolean)

    true 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
    # Owner can mark arrived if reservation is editable and not already arrived
    editable? && !object.arrived
  else
    # Non-owner uses same logic for summary objects
    editable? && !object.arrived
  end
end

#mark_no_show?(by_owner: false) ⇒ Boolean

Check if reservation can be marked as no show

Parameters:

  • by_owner (Boolean) (defaults to: false)

    whether the action is performed by owner

Returns:

  • (Boolean)

    true 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)
  # Both owner and non-owner use the same logic for summary objects
  editable? && !object.no_show
end

#new?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


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
    # OPTIMIZED: Use stored column directly instead of JSON
    object.custom_sms_sent_by_owner == true
  end
end

#show?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


39
40
41
# File 'app/policies/reservation_summary_policy.rb', line 39

def update?
  show? && editable?
end

#valid_user?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/policies/reservation_summary_policy.rb', line 17

def valid_user?
  object.user_id.present?
end