Blocco 2 - Esiti delle azioni Livewire come avvisi (trait Avvisa) invece di flash che comparivano alla pagina dopo. - PDF, miniature e versioni dei territori non più serviti da nginx su /storage: TerritorioFileController con login, permessi e cache privata. - Ripristino tutto o niente: verifica dell'archivio, una transazione con import, piantine, blocco account e scambio dei file annullabile. - Backup formato 2 con piantine, storico PDF e area KML. - Posto unico preso in un passo (Cache::lock) e rispettato anche da import XML e PDF. - Import PDF da cartella: abbinamento corretto (1-A, 12 B, ambigui), caricamento a lotti, file non PDF ignorati, PDF sostituito nello storico. - L'import XML elimina i file dei territori che non usa più; comando territori:file-orfani per quelli accumulati prima. Blocco 3 - Password attuale richiesta al cambio volontario; AuthenticateSession chiude le sessioni aperte altrove. - Niente nomi dei proclamatori in chiaro nel registro attività. - Export XML senza remember_token; chi riceve l'hash dal file deve cambiare password. - Campagne: ultimo giorno incluso, percentuale sui territori distinti. - Coda: retry_after 960 s, stop_grace_period 16m, Redis volatile-lru, impostazioni rilette a ogni job. - Azzeramento che cancella anche piantine, area KML e anteprime. - Pulsanti profilo e menu che non si nascondevano; icona del sito. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
114 lines
3.7 KiB
PHP
114 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Assegnazioni;
|
|
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
use App\Models\Assegnazione;
|
|
use App\Models\Campagna;
|
|
|
|
class Rientra extends Component
|
|
{
|
|
public Assegnazione $assegnazione;
|
|
public string $returned_at = '';
|
|
public bool $showCampaignPrompt = false;
|
|
|
|
// Derived server-side by checkCampaign() and never bound in the view.
|
|
// Without #[Locked] the client can inject an arbitrary campaign id into
|
|
// the update payload and have the assignment counted toward a campaign it
|
|
// has no date overlap with (or hit an FK violation with a bogus id).
|
|
#[Locked]
|
|
public ?int $campagna_id = null;
|
|
|
|
public bool $counted_in_campaign = false;
|
|
|
|
public function mount(Assegnazione $assegnazione)
|
|
{
|
|
$this->assegnazione = $assegnazione->load(['territorio', 'proclamatore']);
|
|
|
|
if ($assegnazione->returned_at) {
|
|
abort(404, 'Assegnazione già rientrata.');
|
|
}
|
|
|
|
$this->returned_at = now()->format('Y-m-d');
|
|
$this->checkCampaign();
|
|
}
|
|
|
|
public function updatedReturnedAt()
|
|
{
|
|
$this->checkCampaign();
|
|
}
|
|
|
|
protected function checkCampaign()
|
|
{
|
|
if (!$this->returned_at) {
|
|
$this->showCampaignPrompt = false;
|
|
return;
|
|
}
|
|
|
|
$returnDate = \Carbon\Carbon::parse($this->returned_at);
|
|
$campagna = $this->assegnazione->campagnaApplicabile($returnDate);
|
|
|
|
if ($campagna) {
|
|
$this->showCampaignPrompt = true;
|
|
$this->campagna_id = $campagna->id;
|
|
} else {
|
|
$this->showCampaignPrompt = false;
|
|
$this->campagna_id = null;
|
|
$this->counted_in_campaign = false;
|
|
}
|
|
}
|
|
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'returned_at' => 'required|date|after_or_equal:' . $this->assegnazione->assigned_at->format('Y-m-d') . '|before_or_equal:today',
|
|
];
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$this->validate();
|
|
|
|
// mount() rejects an already-returned assignment, but the component
|
|
// state persists across requests — two open tabs would both submit and
|
|
// the second would overwrite returned_at/returned_by and log a
|
|
// duplicate activity entry. Re-check against the current row.
|
|
abort_if($this->assegnazione->fresh()?->returned_at !== null, 409, 'Assegnazione già rientrata.');
|
|
|
|
$returnDate = \Carbon\Carbon::parse($this->returned_at);
|
|
|
|
$this->assegnazione->update([
|
|
'returned_at' => $returnDate,
|
|
'returned_by' => auth()->id(),
|
|
'campaign_id' => $this->counted_in_campaign ? $this->campagna_id : null,
|
|
'counted_in_campaign' => $this->counted_in_campaign,
|
|
]);
|
|
|
|
$territorio = $this->assegnazione->territorio;
|
|
$proclamatore = $this->assegnazione->proclamatore;
|
|
|
|
activity()->causedBy(auth()->user())
|
|
->performedOn($this->assegnazione)
|
|
->withProperties([
|
|
'territorio' => $territorio->numero,
|
|
'proclamatore_id' => $proclamatore->id, // vedi Assegna: niente nomi in chiaro
|
|
'giorni' => $this->assegnazione->giorni,
|
|
'campagna' => $this->counted_in_campaign,
|
|
])
|
|
->log('returned');
|
|
|
|
session()->flash('success', "Territorio {$territorio->numero} rientrato da {$proclamatore->nome_completo} dopo {$this->assegnazione->giorni} giorni.");
|
|
return $this->redirect(route('territori.show', $territorio), navigate: true);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$campagna = $this->campagna_id ? Campagna::find($this->campagna_id) : null;
|
|
|
|
return view('livewire.assegnazioni.rientra', [
|
|
'campagna' => $campagna,
|
|
]);
|
|
}
|
|
}
|