From 33d16751827e0b42fe10bbda6f273d9d035a8fcb Mon Sep 17 00:00:00 2001 From: Vasyka Date: Wed, 5 Aug 2026 19:37:00 +0000 Subject: [PATCH] feat(work-order-dashboard): friendly redirect for missing/foreign WO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of a bare 404 when a work-order id doesn't resolve, redirect to the list with a persistent notification explaining why: either the WO doesn't exist, or it belongs to a different tenant. This is the most common 404 cause: user types /app/work-orders/2/dashboard but WO id 2 is in another tenant's slice — the tenant scope filters it out and find() returns null. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Tenant/Pages/WorkOrderDashboard.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/Filament/Tenant/Pages/WorkOrderDashboard.php b/app/Filament/Tenant/Pages/WorkOrderDashboard.php index 376ab6a..71e9035 100644 --- a/app/Filament/Tenant/Pages/WorkOrderDashboard.php +++ b/app/Filament/Tenant/Pages/WorkOrderDashboard.php @@ -34,16 +34,32 @@ class WorkOrderDashboard extends Page public function mount(int|string $record): void { + $id = (int) $record; $wo = WorkOrder::with([ 'client', 'vehicle', 'master', 'works.labor', 'works.master', 'parts.part', 'payments.user', 'subcontractJobs.subcontractor', - ])->find((int) $record); + ])->find($id); if (! $wo) { - abort(404); + // Diagnose: does it exist in another tenant? + $existsGlobally = WorkOrder::withoutGlobalScopes() + ->where('id', $id)->exists(); + $tenant = app(\App\Tenancy\TenantManager::class)->current(); + $tenantSlug = $tenant?->slug ?? '—'; + $msg = $existsGlobally + ? sprintf(__('Fișa #%d există, dar nu aparține tenantului „%s".'), $id, $tenantSlug) + : sprintf(__('Fișa #%d nu există. Verifică lista de fișe active.'), $id); + \Filament\Notifications\Notification::make() + ->title(__('Fișă indisponibilă')) + ->body($msg) + ->danger() + ->persistent() + ->send(); + redirect('/app/work-orders')->send(); + exit; } $this->record = $wo; }