++ fix: use months for assignment PDF link TTL instead of hours

This commit is contained in:
2026-04-08 15:22:37 +00:00
parent 6f8010514d
commit c585979340
19 changed files with 356 additions and 15 deletions

View File

@@ -4,6 +4,8 @@ namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
class Assegnazione extends Model
{
@@ -17,6 +19,7 @@ class Assegnazione extends Model
'returned_at',
'counted_in_campaign',
'campaign_id',
'pdf_access_code',
'note',
'created_by',
'returned_by',
@@ -79,6 +82,39 @@ class Assegnazione extends Model
return is_null($this->returned_at);
}
public function ensurePdfAccessCode(): string
{
if ($this->pdf_access_code) {
return $this->pdf_access_code;
}
do {
$code = strtoupper(Str::random(12));
} while (static::query()->where('pdf_access_code', $code)->exists());
$this->forceFill(['pdf_access_code' => $code])->saveQuietly();
return $code;
}
public function temporaryPdfViewerUrl(): ?string
{
if (! $this->is_aperta || ! $this->territorio?->pdf_path) {
return null;
}
$months = max(1, (int) Setting::getValue('assignment_link_ttl_hours', 1));
return URL::temporarySignedRoute(
'assignments.pdf.viewer',
now()->addMonths($months),
[
'assignment' => $this->id,
'code' => $this->ensurePdfAccessCode(),
]
);
}
// ─── Scopes ─────────────────────────────────────────────────
public function scopeAperte($query)