From e65942064e3b555885e575aa22315ff02801bde9 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 31 Oct 2024 12:45:29 -0700 Subject: [PATCH 1/4] send emails even if target has no email --- app/Listeners/CheckoutableListener.php | 9 ++++-- routes/web.php | 39 +++++++++++++++++--------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 7d8b5c1c9df5..cf9464a7822a 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -73,14 +73,17 @@ public function onCheckedOut($event) * 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 ($notifiable instanceof User) { 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()) { Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint) diff --git a/routes/web.php b/routes/web.php index e54f4f706a90..e0e623e8da4d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -25,7 +25,9 @@ use App\Http\Controllers\Auth\ResetPasswordController; use App\Livewire\Importer; use App\Models\Asset; +use App\Models\Setting; use App\Models\User; +use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Auth; @@ -552,21 +554,32 @@ [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); + $item = \App\Models\LicenseSeat::find(1); // Load some test data + $admin = User::find(2); + $target = User::find(1); $acceptance = null; // Simulate acceptance data $note = 'Test note'; + $settings = Setting::getSettings(); + $adminCcEmailsArray = []; - $fields = []; - if (($item->model) && ($item->model->fieldset)) { - $fields = $item->model->fieldset->fields; + if($settings->admin_cc_email !== '') { + $adminCcEmail = $settings->admin_cc_email; + $adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail)); + } + $ccEmails = array_filter($adminCcEmailsArray); + if (!empty($target->email)) { + Mail::to($target)->cc($ccEmails)->send( new \App\Mail\CheckoutLicenseMail( + $item, + $admin, + $target, + $acceptance, + $note)); + } else { + Mail::cc($ccEmails)->send(new \App\Mail\CheckoutLicenseMail( + $item, + $admin, + $target, + $acceptance, + $note)); } - - return new \App\Mail\CheckoutAssetMail( - $item, - $admin, - $target, - $acceptance, - $note); }); \ No newline at end of file From 97a449e80ece3e553ec12064e74eae9e291f30f6 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 31 Oct 2024 12:50:13 -0700 Subject: [PATCH 2/4] removes instanceof User check --- app/Listeners/CheckoutableListener.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index cf9464a7822a..58ee68ea00f3 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -73,7 +73,7 @@ public function onCheckedOut($event) * 2. The item has a EULA * 3. The item should send an email at check-in/check-out */ - if ($notifiable instanceof User) { + if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() || (method_exists($event->checkoutable, 'checkin_email') && $event->checkoutable->checkin_email())) { if (!empty($notifiable->email)) { @@ -83,7 +83,7 @@ public function onCheckedOut($event) } Log::info('Sending email, Locale: ' . ($event->checkedOutTo->locale ?? 'default')); } - } + // Send Webhook notification if ($this->shouldSendWebhookNotification()) { Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint) @@ -145,13 +145,16 @@ public function onCheckedIn($event) * 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) From 7a0f79ecd222b23f9e874c354b5881dcaba9d2db Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 31 Oct 2024 12:51:22 -0700 Subject: [PATCH 3/4] remove test route --- routes/web.php | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/routes/web.php b/routes/web.php index e0e623e8da4d..26bbe264f3cf 100644 --- a/routes/web.php +++ b/routes/web.php @@ -553,33 +553,3 @@ '/', [DashboardController::class, 'index'] )->name('home'); -Route::get('/test-email', function() { - $item = \App\Models\LicenseSeat::find(1); // Load some test data - $admin = User::find(2); - $target = User::find(1); - $acceptance = null; // Simulate acceptance data - $note = 'Test note'; - $settings = Setting::getSettings(); - $adminCcEmailsArray = []; - - if($settings->admin_cc_email !== '') { - $adminCcEmail = $settings->admin_cc_email; - $adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail)); - } - $ccEmails = array_filter($adminCcEmailsArray); - if (!empty($target->email)) { - Mail::to($target)->cc($ccEmails)->send( new \App\Mail\CheckoutLicenseMail( - $item, - $admin, - $target, - $acceptance, - $note)); - } else { - Mail::cc($ccEmails)->send(new \App\Mail\CheckoutLicenseMail( - $item, - $admin, - $target, - $acceptance, - $note)); - } -}); \ No newline at end of file From 3791380764fa0ddffeb94d5c5b14d1ae2357bab6 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 31 Oct 2024 12:52:47 -0700 Subject: [PATCH 4/4] remove unused uses --- routes/web.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/routes/web.php b/routes/web.php index 26bbe264f3cf..9d9d4ab21f14 100644 --- a/routes/web.php +++ b/routes/web.php @@ -24,10 +24,6 @@ use App\Http\Controllers\Auth\ForgotPasswordController; use App\Http\Controllers\Auth\ResetPasswordController; use App\Livewire\Importer; -use App\Models\Asset; -use App\Models\Setting; -use App\Models\User; -use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Auth;