From 18760e3fa19d4d37cf16995a4ba5f0b56ba3771a Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 24 Oct 2024 12:21:51 -0700 Subject: [PATCH 01/21] replaces teams notification package, passes integration test --- app/Livewire/SlackSettingsForm.php | 22 ++- .../CheckoutAssetNotification.php | 4 +- composer.json | 2 +- composer.lock | 126 ++++++++++-------- 4 files changed, 79 insertions(+), 75 deletions(-) diff --git a/app/Livewire/SlackSettingsForm.php b/app/Livewire/SlackSettingsForm.php index 45b8b7b41e61..758c2fdac8bb 100644 --- a/app/Livewire/SlackSettingsForm.php +++ b/app/Livewire/SlackSettingsForm.php @@ -7,7 +7,7 @@ use Livewire\Component; use App\Models\Setting; use App\Helpers\Helper; - +use Osama\LaravelTeamsNotification\TeamsNotification; class SlackSettingsForm extends Component { public $webhook_endpoint; @@ -236,20 +236,14 @@ public function googleWebhookTest(){ } public function msTeamTestWebhook(){ - $payload = - [ - "@type" => "MessageCard", - "@context" => "http://schema.org/extensions", - "summary" => trans('mail.snipe_webhook_summary'), - "title" => trans('mail.snipe_webhook_test'), - "text" => trans('general.webhook_test_msg', ['app' => $this->webhook_name]), - ]; - try { - $response = Http::withHeaders([ - 'content-type' => 'applications/json', - ])->post($this->webhook_endpoint, - $payload)->throw(); + $notification = new TeamsNotification($this->webhook_endpoint); + $message = trans('general.webhook_test_msg', ['app' => $this->webhook_name]); + $notification->success()->sendMessage($message); + + $response = Http::withHeaders([ + 'content-type' => 'applications/json', + ])->post($this->webhook_endpoint); if(($response->getStatusCode() == 302)||($response->getStatusCode() == 301)){ return session()->flash('error' , trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint])); diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index b14796fb8c0f..b479e003350d 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -21,6 +21,8 @@ use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; use Illuminate\Support\Facades\Log; +use Osama\LaravelTeamsNotification\TeamsNotification; + class CheckoutAssetNotification extends Notification { use Queueable; @@ -69,7 +71,7 @@ public function via() if (Setting::getSettings()->webhook_selected == 'microsoft' && Setting::getSettings()->webhook_endpoint) { - $notifyBy[] = MicrosoftTeamsChannel::class; + $notifyBy[] = TeamsNotification::class; } diff --git a/composer.json b/composer.json index d3637c3a4b13..b6aceaaa7063 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,6 @@ "intervention/image": "^2.5", "javiereguiluz/easyslugger": "^1.0", "laravel-notification-channels/google-chat": "^3.0", - "laravel-notification-channels/microsoft-teams": "^1.1", "laravel/framework": "^10.0", "laravel/helpers": "^1.4", "laravel/passport": "^11.0", @@ -55,6 +54,7 @@ "nunomaduro/collision": "^7.0", "okvpn/clock-lts": "^1.0", "onelogin/php-saml": "^3.4", + "osa-eg/laravel-teams-notification": "^2.1", "paragonie/constant_time_encoding": "^2.3", "paragonie/sodium_compat": "^1.19", "phpdocumentor/reflection-docblock": "^5.1", diff --git a/composer.lock b/composer.lock index 0631fc275e29..877082bd2b37 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5341bc5be02b3c33e28e46e06dd99f29", + "content-hash": "6eb153ab8627da9552bc84de32665f0f", "packages": [ { "name": "alek13/slack", @@ -2623,63 +2623,6 @@ }, "time": "2024-03-19T06:42:00+00:00" }, - { - "name": "laravel-notification-channels/microsoft-teams", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/laravel-notification-channels/microsoft-teams.git", - "reference": "41d054c5f603ca10951144a87eb8e9652307ce1b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laravel-notification-channels/microsoft-teams/zipball/41d054c5f603ca10951144a87eb8e9652307ce1b", - "reference": "41d054c5f603ca10951144a87eb8e9652307ce1b", - "shasum": "" - }, - "require": { - "guzzlehttp/guzzle": "^6.3 || ^7.0", - "illuminate/notifications": "~5.5 || ~6.0 || ~7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0", - "illuminate/support": "~5.5 || ~6.0 || ~7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0", - "php": ">=7.2" - }, - "require-dev": { - "mockery/mockery": "^1.2.3", - "phpunit/phpunit": "^8.0 || ^9.5 || ^10.5" - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "NotificationChannels\\MicrosoftTeams\\MicrosoftTeamsServiceProvider" - ] - } - }, - "autoload": { - "psr-4": { - "NotificationChannels\\MicrosoftTeams\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Tobias Madner", - "email": "tobias.madner@gmx.at", - "homepage": "https://www.pinpoll.com", - "role": "Developer" - } - ], - "description": "A Laravel Notification Channel for Microsoft Teams", - "homepage": "https://github.com/laravel-notification-channels/microsoft-teams", - "support": { - "issues": "https://github.com/laravel-notification-channels/microsoft-teams/issues", - "source": "https://github.com/laravel-notification-channels/microsoft-teams/tree/1.2.0" - }, - "time": "2024-03-11T15:07:16+00:00" - }, { "name": "laravel/framework", "version": "v10.48.22", @@ -5572,6 +5515,71 @@ ], "time": "2024-05-30T15:14:26+00:00" }, + { + "name": "osa-eg/laravel-teams-notification", + "version": "v2.1.2", + "source": { + "type": "git", + "url": "https://github.com/osa-eg/laravel-teams-notification.git", + "reference": "76173689930aca92b5174a3b102e705279192c0f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/osa-eg/laravel-teams-notification/zipball/76173689930aca92b5174a3b102e705279192c0f", + "reference": "76173689930aca92b5174a3b102e705279192c0f", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": ">=6.5", + "illuminate/support": "^5.5 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0", + "monolog/monolog": ">=1.0", + "php": ">=7.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Osama\\LaravelTeamsNotification\\LaravelTeamsNotificationServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Osama\\LaravelTeamsNotification\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Osama Saad", + "email": "osaad96eg@gmail.com" + } + ], + "description": "A Laravel package to send notifications to Microsoft Teams", + "keywords": [ + "Teams", + "adaptive-card", + "laravel", + "logging", + "microsoft-teams-workflow", + "notification", + "teams-connector", + "teams-webhock", + "teams-workflow", + "teams_logging" + ], + "support": { + "issues": "https://github.com/osa-eg/laravel-teams-notification/issues", + "source": "https://github.com/osa-eg/laravel-teams-notification/tree/v2.1.2" + }, + "time": "2024-09-23T05:24:48+00:00" + }, { "name": "paragonie/constant_time_encoding", "version": "v2.7.0", @@ -16504,5 +16512,5 @@ "ext-pdo": "*" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } From 18da80e6de14f285f59012c75696f55be617a2d4 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 24 Oct 2024 14:24:00 -0700 Subject: [PATCH 02/21] fix checkoutable listener for microsoft teams --- app/Listeners/CheckoutableListener.php | 31 ++++++++++++------- .../CheckoutAssetNotification.php | 28 +++++++++++------ 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index eb6b73809420..6ed213e77098 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -23,6 +23,7 @@ use Illuminate\Support\Facades\Notification; use Exception; use Illuminate\Support\Facades\Log; +use Osama\LaravelTeamsNotification\TeamsNotification; class CheckoutableListener { @@ -48,16 +49,16 @@ public function onCheckedOut($event) // Send email notifications try { - foreach ($notifiables as $notifiable) { - if ($notifiable instanceof User && $notifiable->email != '') { - if (! $event->checkedOutTo->locale){ - Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance)); - } - else { - Notification::send($notifiable, $this->getCheckoutNotification($event, $acceptance)); - } - } - } +// foreach ($notifiables as $notifiable) { +// if ($notifiable instanceof User && $notifiable->email != '') { +// if (! $event->checkedOutTo->locale){ +// Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance)); +// } +// else { +// Notification::send($notifiable, $this->getCheckoutNotification($event, $acceptance)); +// } +// } +// } // Send Webhook notification if ($this->shouldSendWebhookNotification()) { @@ -65,7 +66,15 @@ public function onCheckedOut($event) if (Setting::getSettings()->webhook_selected === 'slack' || Setting::getSettings()->webhook_selected === 'general') { Notification::route('slack', Setting::getSettings()->webhook_endpoint) ->notify($this->getCheckoutNotification($event, $acceptance)); - } else { + } + // Handling Microsoft Teams notification + else if (Setting::getSettings()->webhook_selected === 'microsoft') { + + $message = $this->getCheckoutNotification($event)->toMicrosoftTeams(); + $notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint); + $notification->success()->sendMessage($message[0], $message[1]); // Send the message to Microsoft Teams + } + else { Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint) ->notify($this->getCheckoutNotification($event, $acceptance)); } diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index b479e003350d..518d9d98b26b 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -21,6 +21,7 @@ use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; use Illuminate\Support\Facades\Log; +use Osama\LaravelTeamsNotification\Logging\TeamsLoggingChannel; use Osama\LaravelTeamsNotification\TeamsNotification; class CheckoutAssetNotification extends Notification @@ -147,15 +148,24 @@ public function toMicrosoftTeams() $item = $this->item; $note = $this->note; - return MicrosoftTeamsMessage::create() - ->to($this->settings->webhook_endpoint) - ->type('success') - ->title(trans('mail.Asset_Checkout_Notification')) - ->addStartGroupToSection('activityText') - ->fact(trans('mail.assigned_to'), $target->present()->name) - ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText') - ->fact(trans('mail.Asset_Checkout_Notification') . " by ", $admin->present()->fullName()) - ->fact(trans('mail.notes'), $note ?: ''); + $notification = new TeamsNotification($this->settings->webhook_channel); + $message = trans('mail.Asset_Checkout_Notification'); + $details = [ + trans('mail.assigned_to') => $target->present()->name, + htmlspecialchars_decode($item->present()->name) => '', + trans('mail.Asset_Checkout_Notification'). ' by' => $admin->present()->fullName(), + trans('mail.notes') => $note ?: '', + ]; + return array($message, $details); +// return MicrosoftTeamsMessage::create() +// ->to($this->settings->webhook_endpoint) +// ->type('success') +// ->title() +// ->addStartGroupToSection('activityText') +// ->fact(trans('mail.assigned_to'), $target->present()->name) +// ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText') +// ->fact(trans('mail.Asset_Checkout_Notification') . " by ", $admin->present()->fullName()) +// ->fact(trans('mail.notes'), $note ?: ''); } From e27ff13377f8f783b7230287736eeff63e24c75d Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 24 Oct 2024 14:39:40 -0700 Subject: [PATCH 03/21] adds check in and checkout message for assets --- app/Listeners/CheckoutableListener.php | 49 +++++++++++-------- .../CheckinAssetNotification.php | 20 ++++---- .../CheckoutAssetNotification.php | 16 +----- 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 6ed213e77098..5363da0a9ff0 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -49,16 +49,16 @@ public function onCheckedOut($event) // Send email notifications try { -// foreach ($notifiables as $notifiable) { -// if ($notifiable instanceof User && $notifiable->email != '') { -// if (! $event->checkedOutTo->locale){ -// Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance)); -// } -// else { -// Notification::send($notifiable, $this->getCheckoutNotification($event, $acceptance)); -// } -// } -// } + foreach ($notifiables as $notifiable) { + if ($notifiable instanceof User && $notifiable->email != '') { + if (! $event->checkedOutTo->locale){ + Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance)); + } + else { + Notification::send($notifiable, $this->getCheckoutNotification($event, $acceptance)); + } + } + } // Send Webhook notification if ($this->shouldSendWebhookNotification()) { @@ -116,23 +116,30 @@ public function onCheckedIn($event) $notifiables = $this->getNotifiables($event); // Send email notifications try { - foreach ($notifiables as $notifiable) { - if ($notifiable instanceof User && $notifiable->email != '') { - if (! $event->checkedOutTo->locale){ - Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance)); - } - else { - Notification::send($notifiable, $this->getCheckinNotification($event)); - } - } - } +// foreach ($notifiables as $notifiable) { +// if ($notifiable instanceof User && $notifiable->email != '') { +// if (! $event->checkedOutTo->locale){ +// Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance)); +// } +// else { +// Notification::send($notifiable, $this->getCheckinNotification($event)); +// } +// } +// } // 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 { + } // Handling Microsoft Teams notification + else if (Setting::getSettings()->webhook_selected === 'microsoft') { + + $message = $this->getCheckinNotification($event)->toMicrosoftTeams(); + $notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint); + $notification->success()->sendMessage($message[0], $message[1]); // Send the message to Microsoft Teams + } + else { Notification::route(Setting::getSettings()->webhook_selected, Setting::getSettings()->webhook_endpoint) ->notify($this->getCheckinNotification($event)); } diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 77cd6d9b5a87..7cf3ebd310a9 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -106,16 +106,16 @@ public function toMicrosoftTeams() $item = $this->item; $note = $this->note; - return MicrosoftTeamsMessage::create() - ->to($this->settings->webhook_endpoint) - ->type('success') - ->title(trans('mail.Asset_Checkin_Notification')) - ->addStartGroupToSection('activityText') - ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText') - ->fact(trans('mail.checked_into'), $item->location->name ? $item->location->name : '') - ->fact(trans('mail.Asset_Checkin_Notification')." by ", $admin->present()->fullName()) - ->fact(trans('admin/hardware/form.status'), $item->assetstatus->name) - ->fact(trans('mail.notes'), $note ?: ''); + $message = trans('mail.Asset_Checkin_Notification'); + $details = [ + trans('mail.asset') => htmlspecialchars_decode($item->present()->name), + trans('mail.checked_into') => $item->location->name ? $item->location->name : '', + trans('mail.Asset_Checkin_Notification')." by " => $admin->present()->fullName(), + trans('admin/hardware/form.status') => $item->assetstatus->name, + trans('mail.notes') => $note ?: '', + ]; + + return array($message, $details); } public function toGoogleChat() { diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index 518d9d98b26b..340ee08c6db8 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -141,33 +141,21 @@ public function toSlack() ->content($note); }); } - public function toMicrosoftTeams() + public function toMicrosoftTeams() : array { $target = $this->target; $admin = $this->admin; $item = $this->item; $note = $this->note; - $notification = new TeamsNotification($this->settings->webhook_channel); $message = trans('mail.Asset_Checkout_Notification'); $details = [ trans('mail.assigned_to') => $target->present()->name, - htmlspecialchars_decode($item->present()->name) => '', + trans('mail.asset') => htmlspecialchars_decode($item->present()->name), trans('mail.Asset_Checkout_Notification'). ' by' => $admin->present()->fullName(), trans('mail.notes') => $note ?: '', ]; return array($message, $details); -// return MicrosoftTeamsMessage::create() -// ->to($this->settings->webhook_endpoint) -// ->type('success') -// ->title() -// ->addStartGroupToSection('activityText') -// ->fact(trans('mail.assigned_to'), $target->present()->name) -// ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText') -// ->fact(trans('mail.Asset_Checkout_Notification') . " by ", $admin->present()->fullName()) -// ->fact(trans('mail.notes'), $note ?: ''); - - } public function toGoogleChat() { From cce75a81859d3ff36dee19cf7d0278c17b711549 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 24 Oct 2024 14:48:23 -0700 Subject: [PATCH 04/21] adds check in and checkout messag for accessories --- app/Listeners/CheckoutableListener.php | 20 +++++++-------- .../CheckinAccessoryNotification.php | 20 +++++++-------- .../CheckoutAccessoryNotification.php | 25 ++++++++----------- 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 5363da0a9ff0..ba19d68f2065 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -49,16 +49,16 @@ public function onCheckedOut($event) // Send email notifications try { - foreach ($notifiables as $notifiable) { - if ($notifiable instanceof User && $notifiable->email != '') { - if (! $event->checkedOutTo->locale){ - Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance)); - } - else { - Notification::send($notifiable, $this->getCheckoutNotification($event, $acceptance)); - } - } - } +// foreach ($notifiables as $notifiable) { +// if ($notifiable instanceof User && $notifiable->email != '') { +// if (! $event->checkedOutTo->locale){ +// Notification::locale(Setting::getSettings()->locale)->send($notifiable, $this->getCheckoutNotification($event, $acceptance)); +// } +// else { +// Notification::send($notifiable, $this->getCheckoutNotification($event, $acceptance)); +// } +// } +// } // Send Webhook notification if ($this->shouldSendWebhookNotification()) { diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php index 7e033f1870bd..300e460902fa 100644 --- a/app/Notifications/CheckinAccessoryNotification.php +++ b/app/Notifications/CheckinAccessoryNotification.php @@ -104,17 +104,15 @@ public function toMicrosoftTeams() $item = $this->item; $note = $this->note; - return MicrosoftTeamsMessage::create() - ->to($this->settings->webhook_endpoint) - ->type('success') - ->addStartGroupToSection('activityTitle') - ->title(trans('Accessory_Checkin_Notification')) - ->addStartGroupToSection('activityText') - ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') - ->fact(trans('mail.checked_into'), $item->location->name ? $item->location->name : '') - ->fact(trans('mail.Accessory_Checkin_Notification')." by ", $admin->present()->fullName()) - ->fact(trans('admin/consumables/general.remaining'), $item->numRemaining()) - ->fact(trans('mail.notes'), $note ?: ''); + $message = trans('mail.Accessory_Checkin_Notification'); + $details = [ + trans('mail.accessory_name') => htmlspecialchars_decode($item->present()->name), + trans('mail.checked_into') => $item->location->name ? $item->location->name : '', + trans('mail.Accessory_Checkin_Notification'). ' by' => $admin->present()->fullName(), + trans('admin/consumables/general.remaining')=> $item->numRemaining(), + trans('mail.notes') => $note ?: '', + ]; + return array($message, $details); } public function toGoogleChat() { diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php index 721ba7f6a4b5..c862e94d0c5c 100644 --- a/app/Notifications/CheckoutAccessoryNotification.php +++ b/app/Notifications/CheckoutAccessoryNotification.php @@ -120,20 +120,17 @@ public function toMicrosoftTeams() $item = $this->item; $note = $this->note; - return MicrosoftTeamsMessage::create() - ->to($this->settings->webhook_endpoint) - ->type('success') - ->addStartGroupToSection('activityTitle') - ->title(trans('mail.Accessory_Checkout_Notification')) - ->addStartGroupToSection('activityText') - ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') - ->fact(trans('mail.assigned_to'), $target->present()->name) - ->fact(trans('general.qty'), $this->checkout_qty) - ->fact(trans('mail.checkedout_from'), $item->location->name ? $item->location->name : '') - ->fact(trans('mail.Accessory_Checkout_Notification') . " by ", $admin->present()->fullName()) - ->fact(trans('admin/consumables/general.remaining'), $item->numRemaining()) - ->fact(trans('mail.notes'), $note ?: ''); - + $message = trans('mail.Accessory_Checkout_Notification'); + $details = [ + trans('mail.assigned_to') => $target->present()->name, + trans('mail.accessory_name') => htmlspecialchars_decode($item->present()->name), + trans('general.qty') => $this->checkout_qty, + trans('mail.checkedout_from') => $item->location->name ? $item->location->name : '', + trans('mail.Accessory_Checkout_Notification'). ' by' => $admin->present()->fullName(), + trans('admin/consumables/general.remaining')=> $item->numRemaining(), + trans('mail.notes') => $note ?: '', + ]; + return array($message, $details); } public function toGoogleChat() { From 278bc5e52a133189cfaf5348d709dcf229229e2f Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 24 Oct 2024 14:59:10 -0700 Subject: [PATCH 05/21] ads check in and checkout message for license seats --- .../CheckinLicenseSeatNotification.php | 21 +++++++++---------- .../CheckoutLicenseSeatNotification.php | 20 ++++++++---------- resources/lang/en-US/mail.php | 1 + 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/app/Notifications/CheckinLicenseSeatNotification.php b/app/Notifications/CheckinLicenseSeatNotification.php index 289e63a16247..9fdb0521d2b6 100644 --- a/app/Notifications/CheckinLicenseSeatNotification.php +++ b/app/Notifications/CheckinLicenseSeatNotification.php @@ -110,17 +110,16 @@ public function toMicrosoftTeams() $item = $this->item; $note = $this->note; - return MicrosoftTeamsMessage::create() - ->to($this->settings->webhook_endpoint) - ->type('success') - ->addStartGroupToSection('activityTitle') - ->title(trans('mail.License_Checkin_Notification')) - ->addStartGroupToSection('activityText') - ->fact(htmlspecialchars_decode($item->present()->name), '', 'header') - ->fact(trans('mail.License_Checkin_Notification')." by ", $admin->present()->fullName() ?: 'CLI tool') - ->fact(trans('mail.checkedin_from'), $target->present()->fullName()) - ->fact(trans('admin/consumables/general.remaining'), $item->availCount()->count()) - ->fact(trans('mail.notes'), $note ?: ''); + $message = trans('mail.License_Checkin_Notification'); + $details = [ + trans('mail.checkedin_from')=> $target->present()->fullName(), + trans('mail.license_for') => htmlspecialchars_decode($item->present()->name), + trans('mail.License_Checkin_Notification')." by " => $admin->present()->fullName() ?: 'CLI tool', + trans('admin/consumables/general.remaining') => $item->availCount()->count(), + trans('mail.notes') => $note ?: '', + ]; + + return array($message, $details); } public function toGoogleChat() { diff --git a/app/Notifications/CheckoutLicenseSeatNotification.php b/app/Notifications/CheckoutLicenseSeatNotification.php index 8e0273c66e7d..769b1f9e4aa1 100644 --- a/app/Notifications/CheckoutLicenseSeatNotification.php +++ b/app/Notifications/CheckoutLicenseSeatNotification.php @@ -125,17 +125,15 @@ public function toMicrosoftTeams() $item = $this->item; $note = $this->note; - return MicrosoftTeamsMessage::create() - ->to($this->settings->webhook_endpoint) - ->type('success') - ->addStartGroupToSection('activityTitle') - ->title(trans('mail.License_Checkout_Notification')) - ->addStartGroupToSection('activityText') - ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') - ->fact(trans('mail.License_Checkout_Notification')." by ", $admin->present()->fullName()) - ->fact(trans('mail.assigned_to'), $target->present()->fullName()) - ->fact(trans('admin/consumables/general.remaining'), $item->availCount()->count()) - ->fact(trans('mail.notes'), $note ?: ''); + $message = trans('mail.License_Checkout_Notification'); + $details = [ + trans('mail.assigned_to') => $target->present()->fullName(), + trans('mail.license_for') => htmlspecialchars_decode($item->present()->name), + trans('mail.License_Checkout_Notification').' by' => $admin->present()->fullName(), + trans('admin/consumables/general.remaining') => $item->availCount()->count(), + trans('mail.notes') => $note ?: '', + ]; + return array($message, $details); } public function toGoogleChat() { diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index 72fb70db803c..76c0c1773d28 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -23,6 +23,7 @@ 'Item_Requested' => 'Item Requested', 'License_Checkin_Notification' => 'License checked in', 'License_Checkout_Notification' => 'License checked out', + 'license_for' => 'License for', 'Low_Inventory_Report' => 'Low Inventory Report', 'a_user_canceled' => 'A user has canceled an item request on the website', 'a_user_requested' => 'A user has requested an item on the website', From 6f0c1b12b18901bc335bfdda328777399436386c Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 24 Oct 2024 15:04:54 -0700 Subject: [PATCH 06/21] this adds check out message for consumables --- .../CheckoutConsumableNotification.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/Notifications/CheckoutConsumableNotification.php b/app/Notifications/CheckoutConsumableNotification.php index c974134fe60f..d66509b46abc 100644 --- a/app/Notifications/CheckoutConsumableNotification.php +++ b/app/Notifications/CheckoutConsumableNotification.php @@ -127,17 +127,16 @@ public function toMicrosoftTeams() $item = $this->item; $note = $this->note; - return MicrosoftTeamsMessage::create() - ->to($this->settings->webhook_endpoint) - ->type('success') - ->addStartGroupToSection('activityTitle') - ->title(trans('mail.Consumable_checkout_notification')) - ->addStartGroupToSection('activityText') - ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') - ->fact(trans('mail.Consumable_checkout_notification')." by ", $admin->present()->fullName()) - ->fact(trans('mail.assigned_to'), $target->present()->fullName()) - ->fact(trans('admin/consumables/general.remaining'), $item->numRemaining()) - ->fact(trans('mail.notes'), $note ?: ''); + $message = trans('mail.Consumable_checkout_notification'); + $details = [ + trans('mail.assigned_to') => $target->present()->fullName(), + trans('mail.item') => htmlspecialchars_decode($item->present()->name), + trans('mail.Consumable_checkout_notification').' by' => $admin->present()->fullName(), + trans('admin/consumables/general.remaining') => $item->numRemaining(), + trans('mail.notes') => $note ?: '', + ]; + + return array($message, $details); } public function toGoogleChat() { From b987b3dc005400e2c5042fc47be7d134e86c4314 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 28 Oct 2024 10:57:48 -0700 Subject: [PATCH 07/21] adds back the laravel channels package and applies a deprecated check --- app/Livewire/SlackSettingsForm.php | 36 ++++++++++++++---- composer.json | 1 + composer.lock | 59 +++++++++++++++++++++++++++++- 3 files changed, 87 insertions(+), 9 deletions(-) diff --git a/app/Livewire/SlackSettingsForm.php b/app/Livewire/SlackSettingsForm.php index 758c2fdac8bb..57f811c3d1a2 100644 --- a/app/Livewire/SlackSettingsForm.php +++ b/app/Livewire/SlackSettingsForm.php @@ -4,6 +4,7 @@ use GuzzleHttp\Client; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Str; use Livewire\Component; use App\Models\Setting; use App\Helpers\Helper; @@ -19,6 +20,7 @@ class SlackSettingsForm extends Component public $webhook_placeholder; public $webhook_icon; public $webhook_selected; + public $teams_webhook_deprecated; public array $webhook_text; public Setting $setting; @@ -235,15 +237,33 @@ public function googleWebhookTest(){ } } public function msTeamTestWebhook(){ + $this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows'); + try { - try { - $notification = new TeamsNotification($this->webhook_endpoint); - $message = trans('general.webhook_test_msg', ['app' => $this->webhook_name]); - $notification->success()->sendMessage($message); - - $response = Http::withHeaders([ - 'content-type' => 'applications/json', - ])->post($this->webhook_endpoint); + if($this->teams_webhook_deprecated){ + //will use the deprecated webhook format + $payload = + [ + "@type" => "MessageCard", + "@context" => "http://schema.org/extensions", + "summary" => trans('mail.snipe_webhook_summary'), + "title" => trans('mail.snipe_webhook_test'), + "text" => trans('general.webhook_test_msg', ['app' => $this->webhook_name]), + ]; + $response = Http::withHeaders([ + 'content-type' => 'applications/json', + ])->post($this->webhook_endpoint, + $payload)->throw(); + } + else { + $notification = new TeamsNotification($this->webhook_endpoint); + $message = trans('general.webhook_test_msg', ['app' => $this->webhook_name]); + $notification->success()->sendMessage($message); + + $response = Http::withHeaders([ + 'content-type' => 'applications/json', + ])->post($this->webhook_endpoint); + } if(($response->getStatusCode() == 302)||($response->getStatusCode() == 301)){ return session()->flash('error' , trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint])); diff --git a/composer.json b/composer.json index b6aceaaa7063..865878280c5c 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "intervention/image": "^2.5", "javiereguiluz/easyslugger": "^1.0", "laravel-notification-channels/google-chat": "^3.0", + "laravel-notification-channels/microsoft-teams": "^1.2", "laravel/framework": "^10.0", "laravel/helpers": "^1.4", "laravel/passport": "^11.0", diff --git a/composer.lock b/composer.lock index 877082bd2b37..b04d7a956953 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6eb153ab8627da9552bc84de32665f0f", + "content-hash": "0750e3a427347b2a56a05a8b9b533d48", "packages": [ { "name": "alek13/slack", @@ -2623,6 +2623,63 @@ }, "time": "2024-03-19T06:42:00+00:00" }, + { + "name": "laravel-notification-channels/microsoft-teams", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/laravel-notification-channels/microsoft-teams.git", + "reference": "41d054c5f603ca10951144a87eb8e9652307ce1b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel-notification-channels/microsoft-teams/zipball/41d054c5f603ca10951144a87eb8e9652307ce1b", + "reference": "41d054c5f603ca10951144a87eb8e9652307ce1b", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^6.3 || ^7.0", + "illuminate/notifications": "~5.5 || ~6.0 || ~7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0", + "illuminate/support": "~5.5 || ~6.0 || ~7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0", + "php": ">=7.2" + }, + "require-dev": { + "mockery/mockery": "^1.2.3", + "phpunit/phpunit": "^8.0 || ^9.5 || ^10.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "NotificationChannels\\MicrosoftTeams\\MicrosoftTeamsServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "NotificationChannels\\MicrosoftTeams\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tobias Madner", + "email": "tobias.madner@gmx.at", + "homepage": "https://www.pinpoll.com", + "role": "Developer" + } + ], + "description": "A Laravel Notification Channel for Microsoft Teams", + "homepage": "https://github.com/laravel-notification-channels/microsoft-teams", + "support": { + "issues": "https://github.com/laravel-notification-channels/microsoft-teams/issues", + "source": "https://github.com/laravel-notification-channels/microsoft-teams/tree/1.2.0" + }, + "time": "2024-03-11T15:07:16+00:00" + }, { "name": "laravel/framework", "version": "v10.48.22", From ed81973fe649355a687dfd5dc70b60d9fdb997c3 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 28 Oct 2024 13:57:42 -0700 Subject: [PATCH 08/21] adds notifications for deprecation --- app/Helpers/Helper.php | 18 ++++++++++++++++++ app/Livewire/SlackSettingsForm.php | 13 ++++++++----- resources/views/layouts/default.blade.php | 9 ++++++--- .../livewire/slack-settings-form.blade.php | 9 ++++++++- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 6c43fec05a19..d70d169be24f 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -16,6 +16,7 @@ use Illuminate\Contracts\Encryption\DecryptException; use Carbon\Carbon; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Str; use Intervention\Image\ImageManagerStatic as Image; use Illuminate\Support\Facades\Session; @@ -708,6 +709,23 @@ public static function generateRandomString($length = 10) return $randomString; } + /** + * A method to be used to handle deprecations and giving notifications, currently handling MS Teams. more can be added when needed. + * + * + * @author [Godfrey Martinez] + * @since [v7.0.14] + * @return array + */ + public static function deprecationCheck(){ + $deprecations = [ + 'ms_teams_deprecated' => array( + 'check' => Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows'), + 'message' => 'The Microsoft Teams webhook URL being used will be deprecated Jan 31st, 2025. Change your webhook URL'), + ]; + + return $deprecations; + } /** * This nasty little method gets the low inventory info for the diff --git a/app/Livewire/SlackSettingsForm.php b/app/Livewire/SlackSettingsForm.php index 57f811c3d1a2..3be8aa627e15 100644 --- a/app/Livewire/SlackSettingsForm.php +++ b/app/Livewire/SlackSettingsForm.php @@ -81,15 +81,17 @@ public function mount() { $this->webhook_channel = $this->setting->webhook_channel; $this->webhook_botname = $this->setting->webhook_botname; $this->webhook_options = $this->setting->webhook_selected; - if($this->webhook_selected == 'microsoft' || $this->webhook_selected == 'google'){ + $this->teams_webhook_deprecated = Str::contains($this->webhook_endpoint, 'workflows'); + if($this->webhook_selected === 'microsoft' || $this->webhook_selected === 'google'){ $this->webhook_channel = '#NA'; } - if($this->setting->webhook_endpoint != null && $this->setting->webhook_channel != null){ $this->isDisabled= ''; } - + if($this->webhook_selected === 'microsoft' && !$this->teams_webhook_deprecated) { + session()->flash('warning', 'The selected Microsoft Teams webhook URL will be deprecated Jan 31st, 2025. Please use a workflow URL. Microsofts Documentation on creating a workflow can be found here.'); + } } public function updated($field) { @@ -111,7 +113,6 @@ public function updatedWebhookSelected() { if($this->webhook_selected == 'microsoft' || $this->webhook_selected == 'google'){ $this->webhook_channel = '#NA'; } - } private function isButtonDisabled() { @@ -128,7 +129,9 @@ private function isButtonDisabled() { public function render() { $this->isButtonDisabled(); + return view('livewire.slack-settings-form'); + } public function testWebhook(){ @@ -237,7 +240,7 @@ public function googleWebhookTest(){ } } public function msTeamTestWebhook(){ - $this->teams_webhook_deprecated = !Str::contains($this->webhook_endpoint, 'workflows'); + try { if($this->teams_webhook_deprecated){ diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 1bf7db6f652a..46341f70cc08 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -268,17 +268,20 @@ @can('admin') @if ($snipeSettings->show_alerts_in_menu=='1') - +