From 0b6c6bf1df0e9ae6ed69aae0af1df21cc482cf9d Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Apr 2025 09:18:50 +0100 Subject: [PATCH] =?UTF-8?q?Send=20email=20to=20CC=20addresses=20even=20if?= =?UTF-8?q?=20the=20target=20doesn=E2=80=99t=20have=20an=20email?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Listeners/CheckoutableListener.php | 55 ++++++++++++++++---------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 0824ae131..5dc4f6936 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -77,20 +77,28 @@ class CheckoutableListener if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() || $this->checkoutableShouldSendEmail($event)) { - //Log::info('Sending checkout email, Locale: ' . ($event->checkedOutTo->locale ?? 'default')); - if (!empty($notifiable)) { - Mail::to($notifiable)->cc($ccEmails)->send($mailable); - } elseif (!empty($ccEmails)) { - Mail::cc($ccEmails)->send($mailable); + + + // Send a checkout email to the admin CC addresses, even if the target has no email + if (!empty($ccEmails)) { + Mail::to($ccEmails)->send($mailable); + Log::info('Checkout Mail sent to CC addresses'); } - Log::info('Checkout Mail sent.'); + + // Send a checkout email to the target if it has an email + if (!empty($notifiable->email)) { + Mail::to($notifiable)->send($mailable); + Log::info('Checkout Mail sent to checkout target'); + } + } } catch (ClientException $e) { Log::debug("Exception caught during checkout email: " . $e->getMessage()); } catch (Exception $e) { Log::debug("Exception caught during checkout email: " . $e->getMessage()); } -// Send Webhook notification + + // Send notification try { if ($this->shouldSendWebhookNotification()) { if ($this->newMicrosoftTeamsWebhookEnabled()) { @@ -169,15 +177,17 @@ class CheckoutableListener * 2. The item has a EULA * 3. The item should send an email at check-in/check-out */ - if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() || - $this->checkoutableShouldSendEmail($event)) { - if (!empty($notifiable)) { - Mail::to($notifiable)->cc($ccEmails)->send($mailable); - } elseif (!empty($ccEmails)){ - Mail::cc($ccEmails)->send($mailable); - } - Log::info('Checkin Mail sent.'); - } + // Send a checkout email to the admins CC addresses, even if the target has no email + if (!empty($ccEmails)) { + Mail::to($ccEmails)->send($mailable); + Log::info('Checkin Mail sent to CC addresses'); + } + + // Send a checkout email to the target if it has an email + if (!empty($notifiable->email)) { + Mail::to($notifiable)->send($mailable); + Log::info('Checkin Mail sent to checkout target'); + } } catch (ClientException $e) { Log::debug("Exception caught during checkin email: " . $e->getMessage()); } catch (Exception $e) { @@ -330,14 +340,17 @@ class CheckoutableListener */ private function getNotifiableUsers($event){ - if($event->checkedOutTo instanceof Asset){ + // If it's assigned to an asset, get that asset's assignedTo object + if ($event->checkedOutTo instanceof Asset){ $event->checkedOutTo->load('assignedTo'); return $event->checkedOutTo->assignedto; - } - else if($event->checkedOutTo instanceof Location) { + + // If it's assigned to a location, get that location's manager object + } elseif ($event->checkedOutTo instanceof Location) { return $event->checkedOutTo->manager; - } - else{ + + // Otherwise just return the assigned to object + } else { return $event->checkedOutTo; } }