Skip to content

A free open source IT asset/license management system

apply array_filter to cc emails to prevent errors

Godfrey M2cc2b2b1dfc3
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index 02f8081e6b..584d3847c6 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -63,7 +63,7 @@ class CheckoutableListener
$adminCcEmail = $settings->admin_cc_email;
$adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail));
}
- $ccEmails = array_merge($alertsEmailsArray, $adminCcEmailsArray);
+ $ccEmails = array_filter(array_merge($alertsEmailsArray, $adminCcEmailsArray));
$notifiable = $event->checkedOutTo;
$mailable = $this->getCheckoutMailType($event, $acceptance);
// Send email notifications
@@ -136,8 +136,7 @@ class CheckoutableListener
$adminCcEmail = $settings->admin_cc_email;
$adminCcEmailsArray = array_map('trim', explode(',', $adminCcEmail));
}
- $ccEmails = array_merge($alertsEmailsArray, $adminCcEmailsArray);
-
+ $ccEmails = array_filter(array_merge($alertsEmailsArray, $adminCcEmailsArray));
$notifiable = $event->checkedOutTo;
$mailable = $this->getCheckinMailType($event);
diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php
index cbc946ba43..721ba7f6a4 100644
--- a/app/Notifications/CheckoutAccessoryNotification.php
+++ b/app/Notifications/CheckoutAccessoryNotification.php
@@ -6,7 +6,6 @@ use App\Models\Accessory;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Bus\Queueable;
-use Illuminate\Notifications\Channels\SlackWebhookChannel;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
@@ -56,7 +55,35 @@ class CheckoutAccessoryNotification extends Notification
}
if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general' ) {
- $notifyBy[] = SlackWebhookChannel::class;
+ $notifyBy[] = 'slack';
+ }
+
+ /**
+ * Only send notifications to users that have email addresses
+ */
+ if ($this->target instanceof User && $this->target->email != '') {
+
+ /**
+ * Send an email if the asset requires acceptance,
+ * so the user can accept or decline the asset
+ */
+ if ($this->item->requireAcceptance()) {
+ $notifyBy[1] = 'mail';
+ }
+
+ /**
+ * Send an email if the item has a EULA, since the user should always receive it
+ */
+ if ($this->item->getEula()) {
+ $notifyBy[1] = 'mail';
+ }
+
+ /**
+ * Send an email if an email should be sent at checkin/checkout
+ */
+ if ($this->item->checkin_email()) {
+ $notifyBy[1] = 'mail';
+ }
}
return $notifyBy;
@@ -136,4 +163,31 @@ class CheckoutAccessoryNotification extends Notification
}
+
+ /**
+ * Get the mail representation of the notification.
+ *
+ * @return \Illuminate\Notifications\Messages\MailMessage
+ */
+ public function toMail()
+ {
+ Log::debug($this->item->getImageUrl());
+ $eula = $this->item->getEula();
+ $req_accept = $this->item->requireAcceptance();
+
+ $accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance);
+
+ return (new MailMessage)->markdown('notifications.markdown.checkout-accessory',
+ [
+ 'item' => $this->item,
+ 'admin' => $this->admin,
+ 'note' => $this->note,
+ 'target' => $this->target,
+ 'eula' => $eula,
+ 'req_accept' => $req_accept,
+ 'accept_url' => $accept_url,
+ 'checkout_qty' => $this->checkout_qty,
+ ])
+ ->subject(trans('mail.Confirm_accessory_delivery'));
+ }
}