Send email to CC addresses even if the target doesn’t have an email

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2025-04-16 09:18:50 +01:00
parent b35181c289
commit 0b6c6bf1df

View file

@ -77,20 +77,28 @@ class CheckoutableListener
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() || if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() ||
$this->checkoutableShouldSendEmail($event)) { $this->checkoutableShouldSendEmail($event)) {
//Log::info('Sending checkout email, Locale: ' . ($event->checkedOutTo->locale ?? 'default'));
if (!empty($notifiable)) {
Mail::to($notifiable)->cc($ccEmails)->send($mailable); // Send a checkout email to the admin CC addresses, even if the target has no email
} elseif (!empty($ccEmails)) { if (!empty($ccEmails)) {
Mail::cc($ccEmails)->send($mailable); 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) { } catch (ClientException $e) {
Log::debug("Exception caught during checkout email: " . $e->getMessage()); Log::debug("Exception caught during checkout email: " . $e->getMessage());
} catch (Exception $e) { } catch (Exception $e) {
Log::debug("Exception caught during checkout email: " . $e->getMessage()); Log::debug("Exception caught during checkout email: " . $e->getMessage());
} }
// Send Webhook notification
// Send notification
try { try {
if ($this->shouldSendWebhookNotification()) { if ($this->shouldSendWebhookNotification()) {
if ($this->newMicrosoftTeamsWebhookEnabled()) { if ($this->newMicrosoftTeamsWebhookEnabled()) {
@ -169,14 +177,16 @@ class CheckoutableListener
* 2. The item has a EULA * 2. The item has a EULA
* 3. The item should send an email at check-in/check-out * 3. The item should send an email at check-in/check-out
*/ */
if ($event->checkoutable->requireAcceptance() || $event->checkoutable->getEula() || // Send a checkout email to the admins CC addresses, even if the target has no email
$this->checkoutableShouldSendEmail($event)) { if (!empty($ccEmails)) {
if (!empty($notifiable)) { Mail::to($ccEmails)->send($mailable);
Mail::to($notifiable)->cc($ccEmails)->send($mailable); Log::info('Checkin Mail sent to CC addresses');
} elseif (!empty($ccEmails)){
Mail::cc($ccEmails)->send($mailable);
} }
Log::info('Checkin 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('Checkin Mail sent to checkout target');
} }
} catch (ClientException $e) { } catch (ClientException $e) {
Log::debug("Exception caught during checkin email: " . $e->getMessage()); Log::debug("Exception caught during checkin email: " . $e->getMessage());
@ -330,14 +340,17 @@ class CheckoutableListener
*/ */
private function getNotifiableUsers($event){ private function getNotifiableUsers($event){
// If it's assigned to an asset, get that asset's assignedTo object
if ($event->checkedOutTo instanceof Asset){ if ($event->checkedOutTo instanceof Asset){
$event->checkedOutTo->load('assignedTo'); $event->checkedOutTo->load('assignedTo');
return $event->checkedOutTo->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; return $event->checkedOutTo->manager;
}
else{ // Otherwise just return the assigned to object
} else {
return $event->checkedOutTo; return $event->checkedOutTo;
} }
} }