From 1ad81bcd9f58b319c0ac612a1b0d9aaa90da52a2 Mon Sep 17 00:00:00 2001 From: 24c02 <163450896+24c02@users.noreply.github.com> Date: Sun, 1 Jun 2025 16:16:29 -0400 Subject: [PATCH] search by tracking number on publicID --- app/controllers/public/lsv_controller.rb | 3 ++- app/controllers/public_ids_controller.rb | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/controllers/public/lsv_controller.rb b/app/controllers/public/lsv_controller.rb index 09c1f26..ea8a108 100644 --- a/app/controllers/public/lsv_controller.rb +++ b/app/controllers/public/lsv_controller.rb @@ -4,7 +4,8 @@ module Public def show @lsv = LSV::SLUGS[params[:slug].to_sym]&.find(params[:id]) - raise ActiveRecord::RecordNotFound unless @lsv && @lsv.email == current_public_user&.email + raise ActiveRecord::RecordNotFound unless @lsv + raise ActiveRecord::RecordNotFound unless @lsv.email == current_public_user&.email || current_user rescue Norairrecord::RecordNotFoundError raise ActiveRecord::RecordNotFound end diff --git a/app/controllers/public_ids_controller.rb b/app/controllers/public_ids_controller.rb index 8019dc7..535968f 100644 --- a/app/controllers/public_ids_controller.rb +++ b/app/controllers/public_ids_controller.rb @@ -42,7 +42,7 @@ class PublicIdsController < ApplicationController clazzes = ActiveRecord::Base.descendants.select { |c| c.included_modules.include?(PublicIdentifiable) } clazz = clazzes.find { |c| c.public_id_prefix == prefix } unless clazz.present? - return redirect_to public_ids_path, alert: "don't think we have that prefix: #{prefix}" + return search_by_tracking_number(params[:id]) end @record = clazz.find_by_public_id(params[:id]) unless @record.present? @@ -58,4 +58,24 @@ class PublicIdsController < ApplicationController flash[:alert] = "Record not found" redirect_to public_ids_path end + + private + + def search_by_tracking_number(tracking_number) + # Search for warehouse orders by tracking number + warehouse_order = Warehouse::Order.find_by(tracking_number: tracking_number) + if warehouse_order + return redirect_to warehouse_order_path(warehouse_order) + end + + lsv = LSV::MarketingShipmentRequest.first_where("{Warehouse–Tracking Number} = '#{tracking_number.gsub("'", "\\'")}'") + + if lsv + return redirect_to show_lsv_path(LSV.slug_for(lsv), lsv.id) + end + + # No package found with this tracking number + flash[:alert] = "nothing found at all." + redirect_to public_ids_path + end end