Skip to content

Commit 24d8706

Browse files
committed
fix: invio mail con allegato a utenti senza i permessi per il modulo Coda di invio
1 parent f5120fd commit 24d8706

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

modules/emails/ajax/complete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
$addResults($fetchEmails('an_sedi', 'email', 'nomesede'));
8888

8989
// Tutti i referenti
90-
$addResults($fetchEmails('an_referenti', 'email', 'nome'));
90+
$addResults($fetchEmails('an_referenti', 'email', 'an_referenti.nome'));
9191

9292
echo json_encode($results);
9393

modules/emails/src/Mail.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222

2323
use Common\SimpleModelTrait;
2424
use Illuminate\Database\Eloquent\Model;
25+
use Models\Module;
2526
use Models\PrintTemplate;
2627
use Models\Upload;
2728
use Models\User;
2829
use Modules\Newsletter\Newsletter;
30+
use Monolog\Logger;
2931

3032
class Mail extends Model
3133
{
@@ -78,7 +80,7 @@ public function addUpload($file_id, $name = null)
7880

7981
// duplica il file
8082
$upload = $file->copia([
81-
'id_module' => \Models\Module::where('name', 'Stato email')->first()->id,
83+
'id_module' => Module::where('name', 'Stato email')->first()->id,
8284
'id_record' => $this->id,
8385
]);
8486

@@ -109,8 +111,20 @@ public function addPrint($print_id, $name = null)
109111
// Genera la stampa come PDF
110112
$print = \Prints::render($print_id, $this->id_record, null, true);
111113

114+
// Verifica che la stampa sia stata generata correttamente
115+
if (!$print || !isset($print['pdf'])) {
116+
$logger = \logger_osm();
117+
$logger->addRecord(Logger::ERROR, 'Impossibile generare il PDF per la stampa: '.$print_id, [
118+
'id_email' => $this->id,
119+
'id_record' => $this->id_record,
120+
'print_id' => $print_id,
121+
]);
122+
123+
return;
124+
}
125+
112126
// Ottieni il modulo "Coda d'invio"
113-
$id_module = \Models\Module::where('name', 'Stato email')->first()->id;
127+
$id_module = Module::where('name', 'Stato email')->first()->id;
114128

115129
$name = $name ?: $print['name'];
116130

@@ -123,6 +137,19 @@ public function addPrint($print_id, $name = null)
123137
'id_record' => $this->id,
124138
]);
125139

140+
// Verifica che l'upload sia stato eseguito correttamente
141+
if (!$upload) {
142+
$logger = \logger_osm();
143+
$logger->addRecord(Logger::ERROR, 'Impossibile salvare l\'allegato PDF per la email', [
144+
'id_email' => $this->id,
145+
'id_record' => $this->id_record,
146+
'print_id' => $print_id,
147+
'filename' => $name,
148+
]);
149+
150+
return;
151+
}
152+
126153
// Collega il file alla tabella em_email_attachment
127154
$this->attachments()->attach($upload->id, ['id_email' => $this->id, 'name' => $name, 'type' => 'print']);
128155
}

src/Models/Upload.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,12 @@ protected static function checkUploadPermissions($data)
491491
return true; // Se non riusciamo a determinare il modulo, permetti per compatibilità
492492
}
493493

494+
// Permetti sempre l'upload di un allegato a un email in invio, tramite il modulo Coda di invio
495+
$email_module = Module::where('name', 'Stato email')->first();
496+
if ($email_module && $id_module == $email_module->id) {
497+
return true;
498+
}
499+
494500
// Verifica permessi in base al tipo di accesso
495501
if (\Permissions::isTokenAccess()) {
496502
// Per accesso tramite token, verifica i permessi del token

0 commit comments

Comments
 (0)