From f270672a3d9219121930ea3ea68bdc5b8647f1c0 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 23 Jan 2024 13:05:39 -0800 Subject: [PATCH] added a location check, to prevent notif blowing up --- app/Listeners/CheckoutableListener.php | 3 +- .../CheckinAccessoryNotification.php | 2 +- .../CheckinAssetNotification.php | 5 ++-- .../CheckoutAccessoryNotification.php | 2 +- .../CheckoutAssetNotification.php | 29 ++++++++++++------- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index ea1a4f036e..162b07d276 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -225,9 +225,10 @@ class CheckoutableListener break; case LicenseSeat::class: $notificationClass = CheckoutLicenseSeatNotification::class; - break; + break; } + return new $notificationClass($event->checkoutable, $event->checkedOutTo, $event->checkedOutBy, $acceptance, $event->note); } diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php index 83a01df410..3a36af7019 100644 --- a/app/Notifications/CheckinAccessoryNotification.php +++ b/app/Notifications/CheckinAccessoryNotification.php @@ -126,7 +126,7 @@ class CheckinAccessoryNotification extends Notification ->title("Accessory Checked In") ->addStartGroupToSection('activityText') ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') - ->fact('Checked into ', $item->location->name) + ->fact('Checked into ', $item->location->name ? $item->location->name : '') ->fact(trans('mail.Accessory_Checkin_Notification')." by ", $admin->present()->fullName()) ->fact('Number Remaining', $item->numRemaining()) ->fact('Notes', $note ?: 'No notes'); diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index e8dffd7ae8..35fa3fdf9d 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -99,11 +99,10 @@ class CheckinAssetNotification extends Notification return MicrosoftTeamsMessage::create() ->to($this->settings->webhook_endpoint) ->type('success') - ->addStartGroupToSection('activityTitle') ->title("Asset Checked in") ->addStartGroupToSection('activityText') - ->fact(htmlspecialchars_decode($item->present()->name), '', 'header') - ->fact('Checked into ', $item->location->name) + ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText') + ->fact('Checked into ', $item->location->name ? $item->location->name : '') ->fact(trans('mail.Asset_Checkin_Notification')." by ", $admin->present()->fullName()) ->fact('Asset Status', $item->assetstatus->name) ->fact('Notes', $note ?: 'No notes'); diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php index 33bed0db60..a44c193b57 100644 --- a/app/Notifications/CheckoutAccessoryNotification.php +++ b/app/Notifications/CheckoutAccessoryNotification.php @@ -116,7 +116,7 @@ class CheckoutAccessoryNotification extends Notification ->title("Accessory Checked Out") ->addStartGroupToSection('activityText') ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') - ->fact('Checked out from ', $item->location->name) + ->fact('Checked out from ', $item->location->name ? $item->location->name : '') ->fact(trans('mail.Accessory_Checkout_Notification')." by ", $admin->present()->fullName()) ->fact('Number Remaining', $item->numRemaining()) ->fact('Notes', $note ?: 'No notes'); diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index b6d31a8b61..29f1cc254b 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -6,6 +6,7 @@ use App\Helpers\Helper; use App\Models\Asset; use App\Models\Setting; use App\Models\User; +use Exception; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; @@ -129,17 +130,23 @@ class CheckoutAssetNotification extends Notification $item = $this->item; $note = $this->note; - return MicrosoftTeamsMessage::create() - ->to($this->settings->webhook_endpoint) - ->type('success') - ->addStartGroupToSection('activityTitle') - ->title("Asset Checked Out") - ->addStartGroupToSection('activityText') - ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') - ->fact('Checked out from ', $item->location->name) - ->fact(trans('mail.Asset_Checkout_Notification')." by ", $admin->present()->fullName()) - ->fact('Asset Status', $item->assetstatus->name) - ->fact('Notes', $note ?: 'No notes'); + try { + + return MicrosoftTeamsMessage::create() + ->to($this->settings->webhook_endpoint) + ->type('success') + ->title("Asset Checked Out") + ->addStartGroupToSection('activityText') + ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText') + ->fact('Checked out from ', $item->location ? $item->location->name : '') + ->fact(trans('mail.Asset_Checkout_Notification') . " by ", $admin->present()->fullName()) + ->fact('Asset Status', $item->assetstatus->name) + ->fact('Notes', $note ?: 'No notes'); + } + catch(Exception $e) { + dd($e); + + } } /**