36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Assegnazione;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
class ShortPdfLinkController extends Controller
|
|
{
|
|
public function __invoke(string $code): RedirectResponse|View
|
|
{
|
|
$assignment = Assegnazione::where('pdf_access_code', $code)->firstOrFail();
|
|
|
|
abort_unless($assignment->is_aperta, 403);
|
|
abort_unless($assignment->territorio?->pdf_path, 404);
|
|
|
|
// Unauthenticated users (proclamatori) are subject to the link expiry:
|
|
// il link scade al raggiungimento della soglia rientro (giorni_per_smarrito).
|
|
if (! auth()->check()) {
|
|
$soglia = max(1, (int) \App\Models\Setting::getValue('giorni_per_smarrito', 120));
|
|
if ($assignment->assigned_at->copy()->addDays($soglia)->isPast()) {
|
|
return view('assignments.link-scaduto', [
|
|
'numero' => $assignment->territorio?->numero,
|
|
]);
|
|
}
|
|
}
|
|
|
|
return redirect()->route('assignments.pdf.viewer', [
|
|
'assignment' => $assignment->id,
|
|
'code' => $code,
|
|
]);
|
|
}
|
|
}
|
|
|