Skip to content

A free open source IT asset/license management system

seperates emails and webhook notifications

Godfrey Mc40209f5000a
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index 5968632fdc..5c7e772976 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -43,30 +43,31 @@ class CheckoutableListener
* Make a checkout acceptance and attach it in the notification
*/
$acceptance = $this->getCheckoutAcceptance($event);
+ $notifiables = $this->getNotifiables($event);
+ // Send email notifications
try {
- if (! $event->checkedOutTo->locale) {
- Notification::locale(Setting::getSettings()->locale)->send(
- $this->getNotifiables($event),
- $this->getCheckoutNotification($event, $acceptance)
- );
- } else {
- Notification::send(
- $this->getNotifiables($event),
- $this->getCheckoutNotification($event, $acceptance)
- );
+ foreach ($notifiables as $notifiable) {
+ if ($notifiable instanceof User && $notifiable->email != '') {
+ if (! $event->checkedOutTo->locale){
+ Notification::locale(Setting::getSettings()->locale)->send($notifiables, $this->getCheckoutNotification($event, $acceptance));
+ }
+ else {
+ Notification::send($notifiable, $this->getCheckoutNotification($event, $acceptance));
+ }
+ }
}
+ // Send Webhook notification
if ($this->shouldSendWebhookNotification()) {
-
- //slack doesn't include the url in its messaging format so this is needed to hit the endpoint
-
- if(Setting::getSettings()->webhook_selected =='slack' || Setting::getSettings()->webhook_selected =='general') {
-
-
- Notification::route('slack', Setting::getSettings()->webhook_endpoint)
- ->notify($this->getCheckoutNotification($event));
- }
+ // Slack doesn't include the URL in its messaging format, so this is needed to hit the endpoint
+ if (Setting::getSettings()->webhook_selected === 'slack' || Setting::getSettings()->webhook_selected === 'general') {
+ Notification::route('slack', Setting::getSettings()->webhook_endpoint)
+ ->notify($this->getCheckoutNotification($event));
+ } else {
+ Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
+ ->notify($this->getCheckoutNotification($event, $acceptance));
+ }
}
} catch (ClientException $e) {
Log::debug("Exception caught during checkout notification: " . $e->getMessage());
@@ -75,6 +76,7 @@ class CheckoutableListener
}
}
+
/**
* Notify the user and post to webhook about the checked in checkoutable
*/
@@ -100,26 +102,29 @@ class CheckoutableListener
}
}
}
-
+ $acceptance = $this->getCheckoutAcceptance($event);
+ $notifiables = $this->getNotifiables($event);
+ // Send email notifications
try {
- // Use default locale
- if (! $event->checkedOutTo->locale) {
- Notification::locale(Setting::getSettings()->locale)->send(
- $this->getNotifiables($event),
- $this->getCheckinNotification($event)
- );
- } else {
- Notification::send(
- $this->getNotifiables($event),
- $this->getCheckinNotification($event)
- );
+ foreach ($notifiables as $notifiable) {
+ if ($notifiable instanceof User && $notifiable->email != '') {
+ if (! $event->checkedOutTo->locale){
+ Notification::locale(Setting::getSettings()->locale)->send($notifiables, $this->getCheckoutNotification($event, $acceptance));
+ }
+ else {
+ Notification::send($notifiable, $this->getCheckinNotification($event, $acceptance));
+ }
+ }
}
- //slack doesn't include the url in its messaging format so this is needed to hit the endpoint
- if(Setting::getSettings()->webhook_selected =='slack' || Setting::getSettings()->webhook_selected =='general') {
-
- if ($this->shouldSendWebhookNotification()) {
+ // Send Webhook notification
+ if ($this->shouldSendWebhookNotification()) {
+ // Slack doesn't include the URL in its messaging format, so this is needed to hit the endpoint
+ if (Setting::getSettings()->webhook_selected === 'slack' || Setting::getSettings()->webhook_selected === 'general') {
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
->notify($this->getCheckinNotification($event));
+ } else {
+ Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
+ ->notify($this->getCheckinNotification($event, $acceptance));
}
}