feat(work-order-dashboard): friendly redirect for missing/foreign WO
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) <noreply@anthropic.com>
This commit is contained in:
@@ -34,16 +34,32 @@ class WorkOrderDashboard extends Page
|
|||||||
|
|
||||||
public function mount(int|string $record): void
|
public function mount(int|string $record): void
|
||||||
{
|
{
|
||||||
|
$id = (int) $record;
|
||||||
$wo = WorkOrder::with([
|
$wo = WorkOrder::with([
|
||||||
'client', 'vehicle', 'master',
|
'client', 'vehicle', 'master',
|
||||||
'works.labor', 'works.master',
|
'works.labor', 'works.master',
|
||||||
'parts.part',
|
'parts.part',
|
||||||
'payments.user',
|
'payments.user',
|
||||||
'subcontractJobs.subcontractor',
|
'subcontractJobs.subcontractor',
|
||||||
])->find((int) $record);
|
])->find($id);
|
||||||
|
|
||||||
if (! $wo) {
|
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;
|
$this->record = $wo;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user