diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index b9b176f16..f8c6c8baa 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -74,13 +74,17 @@ class CheckoutableListener * 2. The item has a EULA * 3. The item should send an email at check-in/check-out */ - if ($notifiable instanceof User && $notifiable->email != '') { + if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() || (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) { - Mail::to($notifiable)->cc($ccEmails)->send($mailable); + if (!empty($notifiable->email)) { + Mail::to($notifiable)->cc($ccEmails)->send($mailable); + } else { + Mail::cc($ccEmails)->send($mailable); + } Log::info('Sending email, Locale: ' . ($event->checkedOutTo->locale ?? 'default')); } - } + // Send Webhook notification if ($this->shouldSendWebhookNotification()) { if (Setting::getSettings()->webhook_selected === 'microsoft') { @@ -148,13 +152,16 @@ class CheckoutableListener * 3. The item should send an email at check-in/check-out */ - if ($notifiable instanceof User && $notifiable->email != '') { if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() || (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) { - Mail::to($notifiable)->cc($ccEmails)->send($mailable); + if (!empty($notifiable->email)) { + Mail::to($notifiable)->cc($ccEmails)->send($mailable); + } else { + Mail::cc($ccEmails)->send($mailable); + } Log::info('Sending email, Locale: ' . $event->checkedOutTo->locale); } - } + // Send Webhook notification if ($this->shouldSendWebhookNotification()) { Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint) diff --git a/routes/web.php b/routes/web.php index e54f4f706..9d9d4ab21 100644 --- a/routes/web.php +++ b/routes/web.php @@ -24,8 +24,6 @@ use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Auth\ForgotPasswordController; use App\Http\Controllers\Auth\ResetPasswordController; use App\Livewire\Importer; -use App\Models\Asset; -use App\Models\User; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Auth; @@ -551,22 +549,3 @@ Route::middleware(['auth'])->get( '/', [DashboardController::class, 'index'] )->name('home'); -Route::get('/test-email', function() { - $item = Asset::find(1); // Load some test data - $admin = User::find(1); - $target = User::find(2); - $acceptance = null; // Simulate acceptance data - $note = 'Test note'; - - $fields = []; - if (($item->model) && ($item->model->fieldset)) { - $fields = $item->model->fieldset->fields; - } - - return new \App\Mail\CheckoutAssetMail( - $item, - $admin, - $target, - $acceptance, - $note); -}); \ No newline at end of file