Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/gallagher/parking_approvals.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2658,3 +2658,4 @@ class Place::Parking::Approvals < PlaceOS::Driver
logger.warn(exception: error) { "failed to update process_state #{state} for booking #{booking.id}" }
end
end

35 changes: 31 additions & 4 deletions drivers/gallagher/parking_approvals_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3732,8 +3732,8 @@ DriverSpecs.mock_driver "Place::Parking::Approvals" do
booking_type: "parking",
booking_start: cancel_start,
booking_end: cancel_end,
asset_id: asset,
asset_ids: [asset],
resource_id: asset,
resource_ids: [asset],
user_id: "user-85001",
user_email: "cancel.user@example.com",
user_name: "Cancel User",
Expand Down Expand Up @@ -3772,6 +3772,33 @@ DriverSpecs.mock_driver "Place::Parking::Approvals" do
sleep 100.milliseconds
mailer.times_sent("cancel.user@example.com", "parking_request", "cancelled").should eq(1)

# events that only provide the plural resource_ids are handled too
mailer.reset
publish("staff/booking/changed", {
action: "cancelled",
id: 85003_i64,
booking_type: "parking",
booking_start: cancel_start,
booking_end: cancel_end,
resource_ids: ["asset-inv1"],
user_id: "user-85003",
user_email: "cancel2.user@example.com",
user_name: "Cancel User 2",
booked_by_email: "cancel2.user@example.com",
booked_by_name: "Cancel User 2",
zones: ["zone-building"],
created: now - 500_i64,
last_changed: now,
approved: true,
rejected: false,
deleted: false,
process_state: "access_granted_emailed",
extension_data: {"location" => "INV1"},
}.to_json)
sleep 100.milliseconds
mailer.sent?("cancel2.user@example.com", "parking_request", "cancelled").should eq(true)
staff.last_state(85003_i64).should eq("cancelled_emailed")

# a cancelled booking that was only ever wait-listed -> nothing is sent
mailer.reset
publish("staff/booking/changed", {
Expand All @@ -3780,8 +3807,8 @@ DriverSpecs.mock_driver "Place::Parking::Approvals" do
booking_type: "parking",
booking_start: cancel_start,
booking_end: cancel_end,
asset_id: "unallocated-85002",
asset_ids: ["unallocated-85002"],
resource_id: "unallocated-85002",
resource_ids: ["unallocated-85002"],
user_id: "user-85002",
user_email: "waitlist.user@example.com",
user_name: "Wait List User",
Expand Down
20 changes: 18 additions & 2 deletions drivers/place/booking_model.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,29 @@ class Place::Booking
property booking_end : Int64
property timezone : String?

# events use resource_id instead of asset_id
# events use resource_id/resource_ids instead of asset_id/asset_ids
property asset_id : String?
property asset_ids : Array(String) = [] of String
property resource_id : String?
property resource_ids : Array(String) = [] of String

def asset_id : String
(@asset_id || @resource_id).as(String)
(@asset_id || @resource_id || @asset_ids.first?).as(String)
end

# Staff booking events report the allocated resource(s) as resource_id /
# resource_ids. Normalise them onto asset_ids so callers can use the same
# accessors for API responses and events.
def after_initialize
return unless @asset_ids.empty?

@asset_ids = if !@resource_ids.empty?
@resource_ids
elsif asset = (@asset_id || @resource_id)
[asset]
else
[] of String
end
end

property user_id : String
Expand Down
Loading