Skip to content

Commit 5897d37

Browse files
authored
Merge pull request #15763 from Godmartinz/no_to_email_check
Fixed emails not being send if target has no email or if not instance of User. Cc_emails will still be sent.
2 parents 49de070 + 21a27dc commit 5897d37

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

app/Listeners/CheckoutableListener.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ public function onCheckedOut($event)
7474
* 2. The item has a EULA
7575
* 3. The item should send an email at check-in/check-out
7676
*/
77-
if ($notifiable instanceof User && $notifiable->email != '') {
77+
7878
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
7979
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
80-
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
80+
if (!empty($notifiable->email)) {
81+
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
82+
} else {
83+
Mail::cc($ccEmails)->send($mailable);
84+
}
8185
Log::info('Sending email, Locale: ' . ($event->checkedOutTo->locale ?? 'default'));
8286
}
83-
}
87+
8488
// Send Webhook notification
8589
if ($this->shouldSendWebhookNotification()) {
8690
if (Setting::getSettings()->webhook_selected === 'microsoft') {
@@ -148,13 +152,16 @@ public function onCheckedIn($event)
148152
* 3. The item should send an email at check-in/check-out
149153
*/
150154

151-
if ($notifiable instanceof User && $notifiable->email != '') {
152155
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
153156
(method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) {
154-
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
157+
if (!empty($notifiable->email)) {
158+
Mail::to($notifiable)->cc($ccEmails)->send($mailable);
159+
} else {
160+
Mail::cc($ccEmails)->send($mailable);
161+
}
155162
Log::info('Sending email, Locale: ' . $event->checkedOutTo->locale);
156163
}
157-
}
164+
158165
// Send Webhook notification
159166
if ($this->shouldSendWebhookNotification()) {
160167
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)

routes/web.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
use App\Http\Controllers\Auth\ForgotPasswordController;
2525
use App\Http\Controllers\Auth\ResetPasswordController;
2626
use App\Livewire\Importer;
27-
use App\Models\Asset;
28-
use App\Models\User;
2927
use Illuminate\Support\Facades\Route;
3028
use Illuminate\Support\Facades\Auth;
3129

@@ -551,22 +549,3 @@
551549
'/',
552550
[DashboardController::class, 'index']
553551
)->name('home');
554-
Route::get('/test-email', function() {
555-
$item = Asset::find(1); // Load some test data
556-
$admin = User::find(1);
557-
$target = User::find(2);
558-
$acceptance = null; // Simulate acceptance data
559-
$note = 'Test note';
560-
561-
$fields = [];
562-
if (($item->model) && ($item->model->fieldset)) {
563-
$fields = $item->model->fieldset->fields;
564-
}
565-
566-
return new \App\Mail\CheckoutAssetMail(
567-
$item,
568-
$admin,
569-
$target,
570-
$acceptance,
571-
$note);
572-
});

0 commit comments

Comments
 (0)