mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 13:14:07 -08:00
Merge pull request #15524 from Godmartinz/double-notif-bug
Fixed double webhook notifications // Separated email and webhook notifications.
This commit is contained in:
commit
6217cba201
|
@ -11,6 +11,7 @@ use App\Models\Consumable;
|
||||||
use App\Models\LicenseSeat;
|
use App\Models\LicenseSeat;
|
||||||
use App\Models\Recipients\AdminRecipient;
|
use App\Models\Recipients\AdminRecipient;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
|
use App\Models\User;
|
||||||
use App\Notifications\CheckinAccessoryNotification;
|
use App\Notifications\CheckinAccessoryNotification;
|
||||||
use App\Notifications\CheckinAssetNotification;
|
use App\Notifications\CheckinAssetNotification;
|
||||||
use App\Notifications\CheckinLicenseSeatNotification;
|
use App\Notifications\CheckinLicenseSeatNotification;
|
||||||
|
@ -43,30 +44,31 @@ class CheckoutableListener
|
||||||
* Make a checkout acceptance and attach it in the notification
|
* Make a checkout acceptance and attach it in the notification
|
||||||
*/
|
*/
|
||||||
$acceptance = $this->getCheckoutAcceptance($event);
|
$acceptance = $this->getCheckoutAcceptance($event);
|
||||||
|
$notifiables = $this->getNotifiables($event);
|
||||||
|
|
||||||
|
// Send email notifications
|
||||||
try {
|
try {
|
||||||
if (! $event->checkedOutTo->locale) {
|
foreach ($notifiables as $notifiable) {
|
||||||
Notification::locale(Setting::getSettings()->locale)->send(
|
if ($notifiable instanceof User && $notifiable->email != '') {
|
||||||
$this->getNotifiables($event),
|
if (! $event->checkedOutTo->locale){
|
||||||
$this->getCheckoutNotification($event, $acceptance)
|
Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance));
|
||||||
);
|
}
|
||||||
} else {
|
else {
|
||||||
Notification::send(
|
Notification::send($notifiable, $this->getCheckoutNotification($event, $acceptance));
|
||||||
$this->getNotifiables($event),
|
}
|
||||||
$this->getCheckoutNotification($event, $acceptance)
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send Webhook notification
|
||||||
if ($this->shouldSendWebhookNotification()) {
|
if ($this->shouldSendWebhookNotification()) {
|
||||||
|
// Slack doesn't include the URL in its messaging format, so this is needed to hit the endpoint
|
||||||
//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)
|
||||||
if(Setting::getSettings()->webhook_selected =='slack' || Setting::getSettings()->webhook_selected =='general') {
|
->notify($this->getCheckoutNotification($event, $acceptance));
|
||||||
|
} else {
|
||||||
|
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
|
||||||
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
->notify($this->getCheckoutNotification($event, $acceptance));
|
||||||
->notify($this->getCheckoutNotification($event));
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (ClientException $e) {
|
} catch (ClientException $e) {
|
||||||
Log::debug("Exception caught during checkout notification: " . $e->getMessage());
|
Log::debug("Exception caught during checkout notification: " . $e->getMessage());
|
||||||
|
@ -75,6 +77,7 @@ class CheckoutableListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify the user and post to webhook about the checked in checkoutable
|
* Notify the user and post to webhook about the checked in checkoutable
|
||||||
*/
|
*/
|
||||||
|
@ -101,25 +104,28 @@ class CheckoutableListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$notifiables = $this->getNotifiables($event);
|
||||||
|
// Send email notifications
|
||||||
try {
|
try {
|
||||||
// Use default locale
|
foreach ($notifiables as $notifiable) {
|
||||||
if (! $event->checkedOutTo->locale) {
|
if ($notifiable instanceof User && $notifiable->email != '') {
|
||||||
Notification::locale(Setting::getSettings()->locale)->send(
|
if (! $event->checkedOutTo->locale){
|
||||||
$this->getNotifiables($event),
|
Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance));
|
||||||
$this->getCheckinNotification($event)
|
}
|
||||||
);
|
else {
|
||||||
} else {
|
Notification::send($notifiable, $this->getCheckinNotification($event));
|
||||||
Notification::send(
|
}
|
||||||
$this->getNotifiables($event),
|
}
|
||||||
$this->getCheckinNotification($event)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
//slack doesn't include the url in its messaging format so this is needed to hit the endpoint
|
// Send Webhook notification
|
||||||
if(Setting::getSettings()->webhook_selected =='slack' || Setting::getSettings()->webhook_selected =='general') {
|
if ($this->shouldSendWebhookNotification()) {
|
||||||
|
// Slack doesn't include the URL in its messaging format, so this is needed to hit the endpoint
|
||||||
if ($this->shouldSendWebhookNotification()) {
|
if (Setting::getSettings()->webhook_selected === 'slack' || Setting::getSettings()->webhook_selected === 'general') {
|
||||||
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
Notification::route('slack', Setting::getSettings()->webhook_endpoint)
|
||||||
->notify($this->getCheckinNotification($event));
|
->notify($this->getCheckinNotification($event));
|
||||||
|
} else {
|
||||||
|
Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint)
|
||||||
|
->notify($this->getCheckinNotification($event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue