++ fix temporary PDF viewer URLs, which were causing issues with caching and expiring links. Instead, we now generate short-lived URLs that redirect to the PDF viewer route, ensuring that users can access the PDFs without running into expired links. This change affects the Assegnazione model, the ShortPdfLinkController, and the relevant Blade views for assignments and records. Additionally, I've updated the Home Livewire component to calculate and display the average duration of assignments in months, providing more insight into assignment durations on the dashboard.
This commit is contained in:
@@ -3,35 +3,31 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Assegnazione;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class AssignmentPdfController extends Controller
|
||||
{
|
||||
public function viewer(Request $request, Assegnazione $assignment, string $code): View
|
||||
{
|
||||
$this->validateAccess($request, $assignment, $code);
|
||||
$this->validateAccess($assignment, $code);
|
||||
|
||||
$expiresAt = Carbon::createFromTimestamp((int) $request->query('expires'));
|
||||
$pdfUrl = URL::temporarySignedRoute(
|
||||
'assignments.pdf.file',
|
||||
$expiresAt,
|
||||
['assignment' => $assignment->id, 'code' => $code]
|
||||
);
|
||||
$pdfUrl = route('assignments.pdf.file', [
|
||||
'assignment' => $assignment->id,
|
||||
'code' => $code,
|
||||
]);
|
||||
|
||||
return view('assignments.pdf-viewer', [
|
||||
'assignment' => $assignment,
|
||||
'pdfUrl' => $pdfUrl,
|
||||
'pdfUrl' => $pdfUrl,
|
||||
]);
|
||||
}
|
||||
|
||||
public function file(Request $request, Assegnazione $assignment, string $code): StreamedResponse
|
||||
{
|
||||
$this->validateAccess($request, $assignment, $code);
|
||||
$this->validateAccess($assignment, $code);
|
||||
|
||||
$pdfPath = $assignment->territorio?->pdf_path;
|
||||
abort_unless($pdfPath && Storage::disk('public')->exists($pdfPath), 404);
|
||||
@@ -40,17 +36,16 @@ class AssignmentPdfController extends Controller
|
||||
$pdfPath,
|
||||
'territorio-' . $assignment->territorio?->numero . '.pdf',
|
||||
[
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'inline; filename="territorio-' . $assignment->territorio?->numero . '.pdf"',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function validateAccess(Request $request, Assegnazione $assignment, string $code): void
|
||||
protected function validateAccess(Assegnazione $assignment, string $code): void
|
||||
{
|
||||
abort_unless($request->hasValidSignature(), 403);
|
||||
abort_unless($assignment->pdf_access_code && hash_equals($assignment->pdf_access_code, $code), 404);
|
||||
abort_unless($assignment->is_aperta, 403);
|
||||
abort_unless($assignment->territorio?->pdf_path, 404);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user