++ fix prioritario display and add link sent toggle
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Models\Assegnazione;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
@@ -14,6 +15,10 @@ class AssignmentPdfController extends Controller
|
||||
{
|
||||
$this->validateAccess($assignment, $code);
|
||||
|
||||
if ($expired = $this->linkScaduto($assignment)) {
|
||||
return $expired;
|
||||
}
|
||||
|
||||
$pdfUrl = route('assignments.pdf.file', [
|
||||
'assignment' => $assignment->id,
|
||||
'code' => $code,
|
||||
@@ -25,10 +30,14 @@ class AssignmentPdfController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function file(Request $request, Assegnazione $assignment, string $code): StreamedResponse
|
||||
public function file(Request $request, Assegnazione $assignment, string $code): StreamedResponse|View
|
||||
{
|
||||
$this->validateAccess($assignment, $code);
|
||||
|
||||
if ($expired = $this->linkScaduto($assignment)) {
|
||||
return $expired;
|
||||
}
|
||||
|
||||
$pdfPath = $assignment->territorio?->pdf_path;
|
||||
abort_unless($pdfPath && Storage::disk('public')->exists($pdfPath), 404);
|
||||
|
||||
@@ -48,4 +57,22 @@ class AssignmentPdfController extends Controller
|
||||
abort_unless($assignment->is_aperta, 403);
|
||||
abort_unless($assignment->territorio?->pdf_path, 404);
|
||||
}
|
||||
|
||||
protected function linkScaduto(Assegnazione $assignment): ?View
|
||||
{
|
||||
if (auth()->check()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ttlMonths = max(1, (int) \App\Models\Setting::getValue('assignment_link_ttl_hours', 1));
|
||||
|
||||
if ($assignment->assigned_at->copy()->addMonths($ttlMonths)->isPast()) {
|
||||
return view('assignments.link-scaduto', [
|
||||
'numero' => $assignment->territorio?->numero,
|
||||
]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user