From 93ef8317e8668c928a18331963d0d2c21bbe2301 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 17 Jan 2024 11:49:31 -0800 Subject: [PATCH 01/13] added payload, new MS webhook test method --- app/Http/Livewire/SlackSettingsForm.php | 62 +++++++++++++++++++ .../CheckinAssetNotification.php | 40 ++++++++++++ .../livewire/slack-settings-form.blade.php | 8 ++- 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index 7fc53c7818..396dd5c08f 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -48,6 +48,12 @@ class SlackSettingsForm extends Component "placeholder" => "", "link" => "", ), + "ms_teams" => array( + "name" => trans('admin/settings/general.ms_teams'), + "icon" => "fa-brands fa-microsoft", + "placeholder" => "https://abcd.webhook.office.com/webhookb2/XXXXXXX", + "link" => "", + ), ]; $this->setting = Setting::getSettings(); @@ -178,4 +184,60 @@ class SlackSettingsForm extends Component } } + public function msTeamTestWebhook(){ + $webhook = new Client([ + 'base_url' => e($this->webhook_endpoint), + 'defaults' => [ + 'exceptions' => false, + ], + 'allow_redirects' => false, + ]); + + $payload = json_encode( + [ + "@type"=> "MessageCard", + "@context"=> "http://schema.org/extensions", + "themeColor"=> "0076D7", + "summary"=> trans('mail.Asset_Checkin_Notification'), + "sections"=> [ + "activityTitle"=> "Larry Bryant created a new task", + "activitySubtitle"=> "On Project Tango", + "activityImage"=> "https://adaptivecards.io/content/cats/3.png", + "facts"=> [ + ["name"=> "Assigned to", + "value"=> "Unassigned" + ] + , + ["name"=> "Due date", + "value"=> "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)" + ] + , + ["name"=> "Status", + "value"=> "Not started" + ] + ], + "markdown"=> true + ]] + ); + try { + $test = $webhook->post($this->webhook_endpoint, ['body' => $payload]); + + if(($test->getStatusCode() == 302)||($test->getStatusCode() == 301)){ + return session()->flash('error' , trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint])); + } + $this->isDisabled=''; + $this->save_button = trans('general.save'); + return session()->flash('success' , trans('admin/settings/message.webhook.success', ['webhook_name' => $this->webhook_name])); + + } catch (\Exception $e) { + + $this->isDisabled='disabled'; + $this->save_button = trans('admin/settings/general.webhook_presave'); + return session()->flash('error' , trans('admin/settings/message.webhook.error', ['error_message' => $e->getMessage(), 'app' => $this->webhook_name])); + } + + return session()->flash('error' , trans('admin/settings/message.webhook.error_misc')); + + + } } diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 05e56a9619..2154b42f4a 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -84,6 +84,46 @@ class CheckinAssetNotification extends Notification ->content($note); }); } + public function toMsTeams() + { + $admin = $this->admin; + $item = $this->item; + $note = $this->note; + + $fields = [ + trans('general.administrator') => '<'.$admin->present()->viewUrl().'|'.$admin->present()->fullName().'>', + trans('general.status') => $item->assetstatus->name, + trans('general.location') => ($item->location) ? $item->location->name : '', + ]; + + $payload = json_encode( + [ + "@type"=> "MessageCard", + "@context"=> "http://schema.org/extensions", + "themeColor"=> "0076D7", + "summary"=> trans('mail.Asset_Checkin_Notification'), + "sections"=> [ + "activityTitle"=> "Larry Bryant created a new task", + "activitySubtitle"=> "On Project Tango", + "activityImage"=> "https://adaptivecards.io/content/cats/3.png", + "facts"=> [ + ["name"=> "Assigned to", + "value"=> "Unassigned" + ] + , + ["name"=> "Due date", + "value"=> "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)" + ] + , + ["name"=> "Status", + "value"=> "Not started" + ] + ], + "markdown"=> true + ]] + ); + + } /** * Get the mail representation of the notification. diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index 0c67ca067e..50aa35f550 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -61,9 +61,9 @@
@if (Helper::isDemoMode()) - {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'style'=>'width:100%', 'disabled')) }} + {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'ms_teams' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'style'=>'width:100%', 'disabled')) }} @else - {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'data-minimum-results-for-search' => '-1', 'style'=>'width:100%')) }} + {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'ms_teams' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'data-minimum-results-for-search' => '-1', 'style'=>'width:100%')) }} @endif
@@ -124,7 +124,11 @@ @if($webhook_endpoint != null && $webhook_channel != null)
+ @if($webhook_selected == "ms_teams") {!! trans('admin/settings/general.webhook_test',['app' => ucwords($webhook_selected) ]) !!} From 9f2af40ef231bca3d582d76a302202cd16adce0f Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 17 Jan 2024 13:41:45 -0800 Subject: [PATCH 02/13] adds MS teams integration test --- app/Http/Livewire/SlackSettingsForm.php | 54 +++++++------------ .../lang/en-US/admin/settings/general.php | 1 + .../livewire/slack-settings-form.blade.php | 8 +-- 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index 396dd5c08f..ce33f5a635 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -3,6 +3,7 @@ namespace App\Http\Livewire; use GuzzleHttp\Client; +use Illuminate\Support\Facades\Http; use Livewire\Component; use App\Models\Setting; use App\Helpers\Helper; @@ -48,7 +49,7 @@ class SlackSettingsForm extends Component "placeholder" => "", "link" => "", ), - "ms_teams" => array( + "microsoft" => array( "name" => trans('admin/settings/general.ms_teams'), "icon" => "fa-brands fa-microsoft", "placeholder" => "https://abcd.webhook.office.com/webhookb2/XXXXXXX", @@ -83,6 +84,7 @@ class SlackSettingsForm extends Component $this->webhook_name = $this->webhook_text[$this->webhook_selected]['name']; $this->webhook_icon = $this->webhook_text[$this->webhook_selected]["icon"]; ; $this->webhook_placeholder = $this->webhook_text[$this->webhook_selected]["placeholder"]; + $this->webhook_endpoint = null; $this->webhook_link = $this->webhook_text[$this->webhook_selected]["link"]; if($this->webhook_selected != 'slack'){ $this->isDisabled= ''; @@ -185,44 +187,24 @@ class SlackSettingsForm extends Component } public function msTeamTestWebhook(){ - $webhook = new Client([ - 'base_url' => e($this->webhook_endpoint), - 'defaults' => [ - 'exceptions' => false, - ], - 'allow_redirects' => false, - ]); - $payload = json_encode( - [ - "@type"=> "MessageCard", - "@context"=> "http://schema.org/extensions", - "themeColor"=> "0076D7", - "summary"=> trans('mail.Asset_Checkin_Notification'), - "sections"=> [ - "activityTitle"=> "Larry Bryant created a new task", - "activitySubtitle"=> "On Project Tango", - "activityImage"=> "https://adaptivecards.io/content/cats/3.png", - "facts"=> [ - ["name"=> "Assigned to", - "value"=> "Unassigned" - ] - , - ["name"=> "Due date", - "value"=> "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)" - ] - , - ["name"=> "Status", - "value"=> "Not started" - ] - ], - "markdown"=> true - ]] - ); + $payload = + [ + "@type" => "MessageCard", + "@context" => "http://schema.org/extensions", + "summary" => "Announcement Summary", + "title" => "Snipe-IT Integration Test", + 'text' => trans('general.webhook_test_msg', ['app' => $this->webhook_name]), + ]; + try { - $test = $webhook->post($this->webhook_endpoint, ['body' => $payload]); + $response = Http::withHeaders([ + 'content-type' => 'applications/json', + ])->post($this->webhook_endpoint, + $payload)->throw(); - if(($test->getStatusCode() == 302)||($test->getStatusCode() == 301)){ + + if(($response->getStatusCode() == 302)||($response->getStatusCode() == 301)){ return session()->flash('error' , trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint])); } $this->isDisabled=''; diff --git a/resources/lang/en-US/admin/settings/general.php b/resources/lang/en-US/admin/settings/general.php index c8d6306036..21e5759053 100644 --- a/resources/lang/en-US/admin/settings/general.php +++ b/resources/lang/en-US/admin/settings/general.php @@ -204,6 +204,7 @@ return [ 'integrations' => 'Integrations', 'slack' => 'Slack', 'general_webhook' => 'General Webhook', + 'ms_teams' => 'Microsoft Teams', 'webhook' => ':app', 'webhook_presave' => 'Test to Save', 'webhook_title' => 'Update Webhook Settings', diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index 50aa35f550..4e0296d3ce 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -61,9 +61,9 @@
@if (Helper::isDemoMode()) - {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'ms_teams' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'style'=>'width:100%', 'disabled')) }} + {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'microsoft' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'style'=>'width:100%', 'disabled')) }} @else - {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'ms_teams' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'data-minimum-results-for-search' => '-1', 'style'=>'width:100%')) }} + {{ Form::select('webhook_selected', array('slack' => trans('admin/settings/general.slack'), 'general' => trans('admin/settings/general.general_webhook'), 'microsoft' => trans('admin/settings/general.ms_teams')), old('webhook_selected', $webhook_selected), array('class'=>'select2 form-control', 'aria-label' => 'webhook_selected', 'id' => 'select2', 'data-minimum-results-for-search' => '-1', 'style'=>'width:100%')) }} @endif
@@ -124,8 +124,8 @@ @if($webhook_endpoint != null && $webhook_channel != null)
- @if($webhook_selected == "ms_teams") - Date: Wed, 17 Jan 2024 16:30:27 -0800 Subject: [PATCH 03/13] fixed integration link, added some conditionals --- app/Http/Livewire/SlackSettingsForm.php | 60 +++++++++---------- .../CheckinAssetNotification.php | 42 ++++++------- .../livewire/slack-settings-form.blade.php | 19 +++--- 3 files changed, 58 insertions(+), 63 deletions(-) diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index ce33f5a635..3b1894fadc 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -46,23 +46,24 @@ class SlackSettingsForm extends Component "general"=> array( "name" => trans('admin/settings/general.general_webhook'), "icon" => "fab fa-hashtag", - "placeholder" => "", + "placeholder" => "Insert URL", "link" => "", ), "microsoft" => array( "name" => trans('admin/settings/general.ms_teams'), "icon" => "fa-brands fa-microsoft", "placeholder" => "https://abcd.webhook.office.com/webhookb2/XXXXXXX", - "link" => "", + "link" => "https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=dotnet#create-incoming-webhooks-1", ), ]; $this->setting = Setting::getSettings(); $this->save_button = trans('general.save'); $this->webhook_selected = $this->setting->webhook_selected; - $this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"]; $this->webhook_name = $this->webhook_text[$this->setting->webhook_selected]["name"]; $this->webhook_icon = $this->webhook_text[$this->setting->webhook_selected]["icon"]; + $this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"]; + $this->webhook_link = $this->webhook_text[$this->setting->webhook_selected]["link"]; $this->webhook_endpoint = $this->setting->webhook_endpoint; $this->webhook_channel = $this->setting->webhook_channel; $this->webhook_botname = $this->setting->webhook_botname; @@ -90,6 +91,7 @@ class SlackSettingsForm extends Component $this->isDisabled= ''; $this->save_button = trans('general.save'); } + } private function isButtonDisabled() { @@ -182,44 +184,40 @@ class SlackSettingsForm extends Component $this->setting->save(); session()->flash('success',trans('admin/settings/message.update.success')); - } } public function msTeamTestWebhook(){ - $payload = - [ - "@type" => "MessageCard", - "@context" => "http://schema.org/extensions", - "summary" => "Announcement Summary", - "title" => "Snipe-IT Integration Test", - 'text' => trans('general.webhook_test_msg', ['app' => $this->webhook_name]), - ]; + $payload = + [ + "@type" => "MessageCard", + "@context" => "http://schema.org/extensions", + "summary" => "Snipe-IT Integration Test Summary", + "title" => "Snipe-IT Integration 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(); + $response = Http::withHeaders([ + 'content-type' => 'applications/json', + ])->post($this->webhook_endpoint, + $payload)->throw(); - - if(($response->getStatusCode() == 302)||($response->getStatusCode() == 301)){ - return session()->flash('error' , trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint])); - } - $this->isDisabled=''; - $this->save_button = trans('general.save'); - return session()->flash('success' , trans('admin/settings/message.webhook.success', ['webhook_name' => $this->webhook_name])); - - } catch (\Exception $e) { - - $this->isDisabled='disabled'; - $this->save_button = trans('admin/settings/general.webhook_presave'); - return session()->flash('error' , trans('admin/settings/message.webhook.error', ['error_message' => $e->getMessage(), 'app' => $this->webhook_name])); + if(($response->getStatusCode() == 302)||($response->getStatusCode() == 301)){ + return session()->flash('error' , trans('admin/settings/message.webhook.error_redirect', ['endpoint' => $this->webhook_endpoint])); } + $this->isDisabled=''; + $this->save_button = trans('general.save'); + return session()->flash('success' , trans('admin/settings/message.webhook.success', ['webhook_name' => $this->webhook_name])); + + } catch (\Exception $e) { + + $this->isDisabled='disabled'; + $this->save_button = trans('admin/settings/general.webhook_presave'); + return session()->flash('error' , trans('admin/settings/message.webhook.error', ['error_message' => $e->getMessage(), 'app' => $this->webhook_name])); + } return session()->flash('error' , trans('admin/settings/message.webhook.error_misc')); - - } } diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 2154b42f4a..c6e8597dde 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -97,30 +97,26 @@ class CheckinAssetNotification extends Notification ]; $payload = json_encode( - [ - "@type"=> "MessageCard", - "@context"=> "http://schema.org/extensions", - "themeColor"=> "0076D7", - "summary"=> trans('mail.Asset_Checkin_Notification'), - "sections"=> [ - "activityTitle"=> "Larry Bryant created a new task", - "activitySubtitle"=> "On Project Tango", - "activityImage"=> "https://adaptivecards.io/content/cats/3.png", - "facts"=> [ - ["name"=> "Assigned to", - "value"=> "Unassigned" + [ + "type" => "message", + "attachments" => [ + [ + "contentType" => "application/vnd.microsoft.card.adaptive", + "contentUrl" => null, + "content" => [ + "schema" => "http://adaptivecards.io/schemas/adaptive-card.json", + "type" => "AdaptiveCard", + "version" => "1.2", + "body" => [ + [ + "type" => "TextBlock", + "text" => "For Samples and Templates, see [https://adaptivecards.io/samples](https://adaptivecards.io/samples)" + ] + ] + ] ] - , - ["name"=> "Due date", - "value"=> "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)" - ] - , - ["name"=> "Status", - "value"=> "Not started" - ] - ], - "markdown"=> true - ]] + ] + ] ); } diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index 4e0296d3ce..ad3271bbc7 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -106,16 +106,17 @@ @endif -
-
- {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }} + @if($webhook_selected != 'microsoft') +
+
+ {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }} +
+
+ + {!! $errors->first('webhook_botname', '') !!} +
-
- - {!! $errors->first('webhook_botname', '') !!} -
-
- + @endif @if (!Helper::isDemoMode()) @include('partials.forms.demo-mode') @endif From cdcd8681624d9ff8259f20ecd6969b6010d5d9b3 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 17 Jan 2024 17:31:23 -0800 Subject: [PATCH 04/13] formats check in message for MS Teams --- .../CheckinAssetNotification.php | 44 ++++++------- composer.json | 1 + composer.lock | 61 ++++++++++++++++++- 3 files changed, 78 insertions(+), 28 deletions(-) diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index c6e8597dde..09f55bfc5e 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -10,6 +10,8 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; class CheckinAssetNotification extends Notification { @@ -42,7 +44,10 @@ class CheckinAssetNotification extends Notification * @return array */ public function via() - { + { if (Setting::getSettings()->webhook_selected == 'microsoft'){ + + return [MicrosoftTeamsChannel::class]; + } $notifyBy = []; if (Setting::getSettings()->webhook_endpoint != '') { \Log::debug('use webhook'); @@ -84,40 +89,27 @@ class CheckinAssetNotification extends Notification ->content($note); }); } - public function toMsTeams() + public function toMicrosoftTeams() { $admin = $this->admin; $item = $this->item; $note = $this->note; - - $fields = [ + $button = [ trans('general.administrator') => '<'.$admin->present()->viewUrl().'|'.$admin->present()->fullName().'>', trans('general.status') => $item->assetstatus->name, trans('general.location') => ($item->location) ? $item->location->name : '', ]; - $payload = json_encode( - [ - "type" => "message", - "attachments" => [ - [ - "contentType" => "application/vnd.microsoft.card.adaptive", - "contentUrl" => null, - "content" => [ - "schema" => "http://adaptivecards.io/schemas/adaptive-card.json", - "type" => "AdaptiveCard", - "version" => "1.2", - "body" => [ - [ - "type" => "TextBlock", - "text" => "For Samples and Templates, see [https://adaptivecards.io/samples](https://adaptivecards.io/samples)" - ] - ] - ] - ] - ] - ] - ); + return MicrosoftTeamsMessage::create() + ->to($this->settings->webhook_endpoint) + ->type('success') + ->title("Asset Checked in") + ->fact($item->present()->name, '') + ->fact('Checked into ', $item->location->name) + ->fact(trans('mail.Asset_Checkin_Notification')." by ", $admin->present()->fullName()) + ->fact('Asset Status', $item->assetstatus->name); + + } diff --git a/composer.json b/composer.json index 2a456999e9..a378f15900 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,7 @@ "guzzlehttp/guzzle": "^7.0.1", "intervention/image": "^2.5", "javiereguiluz/easyslugger": "^1.0", + "laravel-notification-channels/microsoft-teams": "^1.1", "laravel/framework": "^8.46", "laravel/helpers": "^1.4", "laravel/passport": "^10.1", diff --git a/composer.lock b/composer.lock index 9c00889854..1d5656cea8 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": "f4f3b6b02d044ed3e54cdd509b01c3dc", + "content-hash": "89580c52de91168aac8321460bd428e2", "packages": [ { "name": "alek13/slack", @@ -3180,6 +3180,63 @@ }, "time": "2015-04-12T19:57:10+00:00" }, + { + "name": "laravel-notification-channels/microsoft-teams", + "version": "v1.1.4", + "source": { + "type": "git", + "url": "https://github.com/laravel-notification-channels/microsoft-teams.git", + "reference": "e2df0129ba430666979eb2ad7033455fd0f6b577" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel-notification-channels/microsoft-teams/zipball/e2df0129ba430666979eb2ad7033455fd0f6b577", + "reference": "e2df0129ba430666979eb2ad7033455fd0f6b577", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^6.3 || ^7.0", + "illuminate/notifications": "~5.5 || ~6.0 || ~7.0 || ^8.0 || ^9.0 || ^10.0", + "illuminate/support": "~5.5 || ~6.0 || ~7.0 || ^8.0 || ^9.0 || ^10.0", + "php": ">=7.2" + }, + "require-dev": { + "mockery/mockery": "^1.2.3", + "phpunit/phpunit": "^8.0|^9.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/v1.1.4" + }, + "time": "2023-01-25T16:56:40+00:00" + }, { "name": "laravel/framework", "version": "v8.83.22", @@ -16961,5 +17018,5 @@ "ext-pdo": "*" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } From befab608f28c1ffd902f7b6658b98fe19b3fdd05 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 17 Jan 2024 17:59:20 -0800 Subject: [PATCH 05/13] cha cha cha changes --- app/Notifications/CheckinAssetNotification.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 09f55bfc5e..0b04af904b 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -103,11 +103,15 @@ class CheckinAssetNotification extends Notification return MicrosoftTeamsMessage::create() ->to($this->settings->webhook_endpoint) ->type('success') + ->addStartGroupToSection('header') ->title("Asset Checked in") - ->fact($item->present()->name, '') + ->fact(htmlspecialchars_decode($item->present()->name), '', 'header') ->fact('Checked into ', $item->location->name) ->fact(trans('mail.Asset_Checkin_Notification')." by ", $admin->present()->fullName()) - ->fact('Asset Status', $item->assetstatus->name); + ->fact('Asset Status', $item->assetstatus->name) + ->fact('Notes', $note ?: 'No notes'); +// ->image($item->getImageUrl(), $item->model()->name, 'header'); + From f049cf5b06e743ce04fce8518bf3a35fa111a7d5 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 22 Jan 2024 10:57:22 -0800 Subject: [PATCH 06/13] adds Asset Check Out Notification --- .../CheckinAssetNotification.php | 16 ++++--------- .../CheckoutAssetNotification.php | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 0b04af904b..e8dffd7ae8 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -44,7 +44,8 @@ class CheckinAssetNotification extends Notification * @return array */ public function via() - { if (Setting::getSettings()->webhook_selected == 'microsoft'){ + { + if (Setting::getSettings()->webhook_selected == 'microsoft'){ return [MicrosoftTeamsChannel::class]; } @@ -94,27 +95,18 @@ class CheckinAssetNotification extends Notification $admin = $this->admin; $item = $this->item; $note = $this->note; - $button = [ - trans('general.administrator') => '<'.$admin->present()->viewUrl().'|'.$admin->present()->fullName().'>', - trans('general.status') => $item->assetstatus->name, - trans('general.location') => ($item->location) ? $item->location->name : '', - ]; return MicrosoftTeamsMessage::create() ->to($this->settings->webhook_endpoint) ->type('success') - ->addStartGroupToSection('header') + ->addStartGroupToSection('activityTitle') ->title("Asset Checked in") + ->addStartGroupToSection('activityText') ->fact(htmlspecialchars_decode($item->present()->name), '', 'header') ->fact('Checked into ', $item->location->name) ->fact(trans('mail.Asset_Checkin_Notification')." by ", $admin->present()->fullName()) ->fact('Asset Status', $item->assetstatus->name) ->fact('Notes', $note ?: 'No notes'); -// ->image($item->getImageUrl(), $item->model()->name, 'header'); - - - - } /** diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index e57825f5c6..b6d31a8b61 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -10,6 +10,8 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; class CheckoutAssetNotification extends Notification { @@ -51,6 +53,10 @@ class CheckoutAssetNotification extends Notification */ public function via() { + if (Setting::getSettings()->webhook_selected == 'microsoft'){ + + return [MicrosoftTeamsChannel::class]; + } $notifyBy = []; if ((Setting::getSettings()) && (Setting::getSettings()->webhook_endpoint != '')) { @@ -117,6 +123,24 @@ class CheckoutAssetNotification extends Notification ->content($note); }); } + public function toMicrosoftTeams() + { + $admin = $this->admin; + $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'); + } /** * Get the mail representation of the notification. From 5a46ef5d5bb61c4e22c1569aa15424e408172569 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 22 Jan 2024 15:30:15 -0800 Subject: [PATCH 07/13] adds Accessory Check in out Notifcations, --- app/Listeners/CheckoutableListener.php | 9 ++- .../CheckinAccessoryNotification.php | 25 ++++++- .../CheckoutAccessoryNotification.php | 28 +++++++- resources/lang/en-US/mail.php | 68 +++++++++---------- 4 files changed, 92 insertions(+), 38 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 17a8a6c1bf..0fcbb902d7 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -58,8 +58,13 @@ class CheckoutableListener } if ($this->shouldSendWebhookNotification()) { - 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') { + + Notification::route('slack', Setting::getSettings()->webhook_endpoint) + ->notify($this->getCheckoutNotification($event)); + } } } catch (ClientException $e) { Log::debug("Exception caught during checkout notification: " . $e->getMessage()); diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php index 7735f7dc11..f3ec95827d 100644 --- a/app/Notifications/CheckinAccessoryNotification.php +++ b/app/Notifications/CheckinAccessoryNotification.php @@ -9,6 +9,8 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; class CheckinAccessoryNotification extends Notification { @@ -35,7 +37,10 @@ class CheckinAccessoryNotification extends Notification */ public function via() { - \Log::debug('via called'); + if (Setting::getSettings()->webhook_selected == 'microsoft'){ + + return [MicrosoftTeamsChannel::class]; + } $notifyBy = []; if (Setting::getSettings()->webhook_endpoint != '') { @@ -108,6 +113,24 @@ class CheckinAccessoryNotification extends Notification ->content($note); }); } + public function toMicrosoftTeams() + { + $admin = $this->admin; + $item = $this->item; + $note = $this->note; + + return MicrosoftTeamsMessage::create() + ->to($this->settings->webhook_endpoint) + ->type('success') + ->addStartGroupToSection('activityTitle') + ->title("Accessory Checked Out") + ->addStartGroupToSection('activityText') + ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') + ->fact('Checked out from ', $item->location->name) + ->fact(trans('mail.Accessory_Checkin_Notification')." by ", $admin->present()->fullName()) + ->fact('Number Remaining', $item->numRemaining()) + ->fact('Notes', $note ?: 'No notes'); + } /** * Get the mail representation of the notification. diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php index f5635d1af0..33aaf41b16 100644 --- a/app/Notifications/CheckoutAccessoryNotification.php +++ b/app/Notifications/CheckoutAccessoryNotification.php @@ -9,6 +9,8 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; class CheckoutAccessoryNotification extends Notification { @@ -37,7 +39,13 @@ class CheckoutAccessoryNotification extends Notification { $notifyBy = []; - if (Setting::getSettings()->webhook_endpoint != '') { + if (Setting::getSettings()->webhook_selected == 'microsoft'){ + +// return [MicrosoftTeamsChannel::class]; + $notifyBy[] = MicrosoftTeamsChannel::class; + } + + if (Setting::getSettings()->webhook_selected == 'slack') { $notifyBy[] = 'slack'; } @@ -96,6 +104,24 @@ class CheckoutAccessoryNotification extends Notification ->content($note); }); } + public function toMicrosoftTeams() + { + $admin = $this->admin; + $item = $this->item; + $note = $this->note; + + return MicrosoftTeamsMessage::create() + ->to($this->settings->webhook_endpoint) + ->type('success') + ->addStartGroupToSection('activityTitle') + ->title("Accessory Checked Out") + ->addStartGroupToSection('activityText') + ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') + ->fact('Checked out from ', $item->location->name) + ->fact(trans('mail.Accessory_Checkout_Notification')." by ", $admin->present()->fullName()) + ->fact('Number Remaining', $item->numRemaining()) + ->fact('Notes', $note ?: 'No notes'); + } /** * Get the mail representation of the notification. diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index 7dd8d6181c..c722a423a9 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -1,10 +1,31 @@ 'A user has accepted an item', - 'acceptance_asset_declined' => 'A user has declined an item', + + 'Accessory_Checkin_Notification' => 'Accessory checked in', + 'Accessory_Checkout_Notification' => 'Accessory checked out', + 'Asset_Checkin_Notification' => 'Asset checked in', + 'Asset_Checkout_Notification' => 'Asset checked out', + 'Confirm_Accessory_Checkin' => 'Accessory checkin confirmation', + 'Confirm_Asset_Checkin' => 'Asset checkin confirmation', + 'Confirm_accessory_delivery' => 'Accessory delivery confirmation', + 'Confirm_asset_delivery' => 'Asset delivery confirmation', + 'Confirm_consumable_delivery' => 'Consumable delivery confirmation', + 'Confirm_license_delivery' => 'License delivery confirmation', + 'Days' => 'Days', + 'Expected_Checkin_Date' => 'An asset checked out to you is due to be checked back in on :date', + 'Expected_Checkin_Notification' => 'Reminder: :name checkin deadline approaching', + 'Expected_Checkin_Report' => 'Expected asset checkin report', + 'Expiring_Assets_Report' => 'Expiring Assets Report.', + 'Expiring_Licenses_Report' => 'Expiring Licenses Report.', + 'Item_Request_Canceled' => 'Item Request Canceled', + 'Item_Requested' => 'Item Requested', + 'License_Checkin_Notification' => 'License checked in', + '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', + 'acceptance_asset_accepted' => 'A user has accepted an item', + 'acceptance_asset_declined' => 'A user has declined an item', 'accessory_name' => 'Accessory Name:', 'additional_notes' => 'Additional Notes:', 'admin_has_created' => 'An administrator has created an account for you on the :web website.', @@ -12,59 +33,46 @@ return [ 'asset_name' => 'Asset Name:', 'asset_requested' => 'Asset requested', 'asset_tag' => 'Asset Tag', + 'assets_warrantee_alert' => 'There is :count asset with a warranty expiring in the next :threshold days.|There are :count assets with warranties expiring in the next :threshold days.', 'assigned_to' => 'Assigned To', 'best_regards' => 'Best regards,', 'canceled' => 'Canceled:', 'checkin_date' => 'Checkin Date:', 'checkout_date' => 'Checkout Date:', - 'click_to_confirm' => 'Please click on the following link to confirm your :web account:', 'click_on_the_link_accessory' => 'Please click on the link at the bottom to confirm that you have received the accessory.', 'click_on_the_link_asset' => 'Please click on the link at the bottom to confirm that you have received the asset.', - 'Confirm_Asset_Checkin' => 'Asset checkin confirmation', - 'Confirm_Accessory_Checkin' => 'Accessory checkin confirmation', - 'Confirm_accessory_delivery' => 'Accessory delivery confirmation', - 'Confirm_license_delivery' => 'License delivery confirmation', - 'Confirm_asset_delivery' => 'Asset delivery confirmation', - 'Confirm_consumable_delivery' => 'Consumable delivery confirmation', + 'click_to_confirm' => 'Please click on the following link to confirm your :web account:', 'current_QTY' => 'Current QTY', - 'Days' => 'Days', 'days' => 'Days', 'expecting_checkin_date' => 'Expected Checkin Date:', 'expires' => 'Expires', - 'Expiring_Assets_Report' => 'Expiring Assets Report.', - 'Expiring_Licenses_Report' => 'Expiring Licenses Report.', 'hello' => 'Hello', 'hi' => 'Hi', 'i_have_read' => 'I have read and agree to the terms of use, and have received this item.', - 'item' => 'Item:', - 'Item_Request_Canceled' => 'Item Request Canceled', - 'Item_Requested' => 'Item Requested', - 'link_to_update_password' => 'Please click on the following link to update your :web password:', - 'login_first_admin' => 'Login to your new Snipe-IT installation using the credentials below:', - 'login' => 'Login:', - 'Low_Inventory_Report' => 'Low Inventory Report', 'inventory_report' => 'Inventory Report', + 'item' => 'Item:', + 'license_expiring_alert' => 'There is :count license expiring in the next :threshold days.|There are :count licenses expiring in the next :threshold days.', + 'link_to_update_password' => 'Please click on the following link to update your :web password:', + 'login' => 'Login:', + 'login_first_admin' => 'Login to your new Snipe-IT installation using the credentials below:', + 'low_inventory_alert' => 'There is :count item that is below minimum inventory or will soon be low.|There are :count items that are below minimum inventory or will soon be low.', 'min_QTY' => 'Min QTY', 'name' => 'Name', 'new_item_checked' => 'A new item has been checked out under your name, details are below.', 'password' => 'Password:', 'password_reset' => 'Password Reset', - 'read_the_terms' => 'Please read the terms of use below.', - 'read_the_terms_and_click' => 'Please read the terms of use below, and click on the link at the bottom to confirm that you read - and agree to the terms of use, and have received the asset.', + 'read_the_terms_and_click' => 'Please read the terms of use below, and click on the link at the bottom to confirm that you read and agree to the terms of use, and have received the asset.', 'requested' => 'Requested:', 'reset_link' => 'Your Password Reset Link', 'reset_password' => 'Click here to reset your password:', + 'rights_reserved' => 'All rights reserved.', 'serial' => 'Serial', 'supplier' => 'Supplier', 'tag' => 'Tag', 'test_email' => 'Test Email from Snipe-IT', 'test_mail_text' => 'This is a test from the Snipe-IT Asset Management System. If you got this, mail is working :)', 'the_following_item' => 'The following item has been checked in: ', - 'low_inventory_alert' => 'There is :count item that is below minimum inventory or will soon be low.|There are :count items that are below minimum inventory or will soon be low.', - 'assets_warrantee_alert' => 'There is :count asset with a warranty expiring in the next :threshold days.|There are :count assets with warranties expiring in the next :threshold days.', - 'license_expiring_alert' => 'There is :count license expiring in the next :threshold days.|There are :count licenses expiring in the next :threshold days.', 'to_reset' => 'To reset your :web password, complete this form:', 'type' => 'Type', 'upcoming-audits' => 'There is :count asset that is coming up for audit within :threshold days.|There are :count assets that are coming up for audit within :threshold days.', @@ -72,14 +80,6 @@ return [ 'username' => 'Username', 'welcome' => 'Welcome :name', 'welcome_to' => 'Welcome to :web!', - 'your_credentials' => 'Your Snipe-IT credentials', - 'Accessory_Checkin_Notification' => 'Accessory checked in', - 'Asset_Checkin_Notification' => 'Asset checked in', - 'Asset_Checkout_Notification' => 'Asset checked out', - 'License_Checkin_Notification' => 'License checked in', - 'Expected_Checkin_Report' => 'Expected asset checkin report', - 'Expected_Checkin_Notification' => 'Reminder: :name checkin deadline approaching', - 'Expected_Checkin_Date' => 'An asset checked out to you is due to be checked back in on :date', 'your_assets' => 'View Your Assets', - 'rights_reserved' => 'All rights reserved.', + 'your_credentials' => 'Your Snipe-IT credentials', ]; From e969f8808c8bf65337b7e958b52ae3b3f153b80c Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 23 Jan 2024 11:10:04 -0800 Subject: [PATCH 08/13] adds licenses ms notifications --- app/Listeners/CheckoutableListener.php | 10 ++++--- .../CheckinAccessoryNotification.php | 4 +-- .../CheckinLicenseSeatNotification.php | 26 ++++++++++++++++++ .../CheckoutAccessoryNotification.php | 1 - .../CheckoutLicenseSeatNotification.php | 27 +++++++++++++++++++ resources/lang/en-US/mail.php | 1 + 6 files changed, 63 insertions(+), 6 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 0fcbb902d7..ea1a4f036e 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -112,11 +112,15 @@ class CheckoutableListener $this->getCheckinNotification($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') { - if ($this->shouldSendWebhookNotification()) { - Notification::route('slack', Setting::getSettings()->webhook_endpoint) - ->notify($this->getCheckinNotification($event)); + if ($this->shouldSendWebhookNotification()) { + Notification::route('slack', Setting::getSettings()->webhook_endpoint) + ->notify($this->getCheckinNotification($event)); + } } + } catch (ClientException $e) { Log::debug("Exception caught during checkout notification: " . $e->getMessage()); } catch (Exception $e) { diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php index f3ec95827d..83a01df410 100644 --- a/app/Notifications/CheckinAccessoryNotification.php +++ b/app/Notifications/CheckinAccessoryNotification.php @@ -123,10 +123,10 @@ class CheckinAccessoryNotification extends Notification ->to($this->settings->webhook_endpoint) ->type('success') ->addStartGroupToSection('activityTitle') - ->title("Accessory Checked Out") + ->title("Accessory Checked In") ->addStartGroupToSection('activityText') ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') - ->fact('Checked out from ', $item->location->name) + ->fact('Checked into ', $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/CheckinLicenseSeatNotification.php b/app/Notifications/CheckinLicenseSeatNotification.php index 2c7fe2fd85..d05f5ef6c1 100644 --- a/app/Notifications/CheckinLicenseSeatNotification.php +++ b/app/Notifications/CheckinLicenseSeatNotification.php @@ -9,6 +9,8 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; class CheckinLicenseSeatNotification extends Notification { @@ -41,6 +43,11 @@ class CheckinLicenseSeatNotification extends Notification { $notifyBy = []; + if (Setting::getSettings()->webhook_selected == 'microsoft'){ + + $notifyBy[] = MicrosoftTeamsChannel::class; + } + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -87,6 +94,25 @@ class CheckinLicenseSeatNotification extends Notification ->content($note); }); } + public function toMicrosoftTeams() + { + $target = $this->target; + $admin = $this->admin; + $item = $this->item; + $note = $this->note; + + return MicrosoftTeamsMessage::create() + ->to($this->settings->webhook_endpoint) + ->type('success') + ->addStartGroupToSection('activityTitle') + ->title("License Checked in") + ->addStartGroupToSection('activityText') + ->fact(htmlspecialchars_decode($item->present()->name), '', 'header') + ->fact(trans('mail.License_Checkin_Notification')." by ", $admin->present()->fullName() ?: 'ClI tool') + ->fact('Checked in from', $target->present()->fullName()) + ->fact('Seats Remaining', $item->availCount()->count()) + ->fact('Notes', $note ?: 'No notes'); + } /** * Get the mail representation of the notification. diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php index 33aaf41b16..33bed0db60 100644 --- a/app/Notifications/CheckoutAccessoryNotification.php +++ b/app/Notifications/CheckoutAccessoryNotification.php @@ -26,7 +26,6 @@ class CheckoutAccessoryNotification extends Notification $this->note = $note; $this->target = $checkedOutTo; $this->acceptance = $acceptance; - $this->settings = Setting::getSettings(); } diff --git a/app/Notifications/CheckoutLicenseSeatNotification.php b/app/Notifications/CheckoutLicenseSeatNotification.php index 2dd6480a30..9a7861444c 100644 --- a/app/Notifications/CheckoutLicenseSeatNotification.php +++ b/app/Notifications/CheckoutLicenseSeatNotification.php @@ -9,6 +9,8 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; class CheckoutLicenseSeatNotification extends Notification { @@ -41,8 +43,14 @@ class CheckoutLicenseSeatNotification extends Notification */ public function via() { + $notifyBy = []; + if (Setting::getSettings()->webhook_selected == 'microsoft'){ + + $notifyBy[] = MicrosoftTeamsChannel::class; + } + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -102,6 +110,25 @@ class CheckoutLicenseSeatNotification extends Notification ->content($note); }); } + public function toMicrosoftTeams() + { + $target = $this->target; + $admin = $this->admin; + $item = $this->item; + $note = $this->note; + + return MicrosoftTeamsMessage::create() + ->to($this->settings->webhook_endpoint) + ->type('success') + ->addStartGroupToSection('activityTitle') + ->title("License Checked Out") + ->addStartGroupToSection('activityText') + ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') + ->fact(trans('mail.License_Checkout_Notification')." by ", $admin->present()->fullName()) + ->fact('Checked out to', $target->present()->fullName()) + ->fact('Seats Remaining', $item->availCount()->count()) + ->fact('Notes', $note ?: 'No notes'); + } /** * Get the mail representation of the notification. diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index c722a423a9..a3632400c4 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -21,6 +21,7 @@ return [ 'Item_Request_Canceled' => 'Item Request Canceled', 'Item_Requested' => 'Item Requested', 'License_Checkin_Notification' => 'License checked in', + 'License_Checkout_Notification' => 'License checked out', '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 7c529df49b94ac37516067fa03f9ca8863118f3c Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 23 Jan 2024 11:21:20 -0800 Subject: [PATCH 09/13] adds consumable checkout ms notification --- .../CheckoutConsumableNotification.php | 26 +++++++++++++++++++ resources/lang/en-US/mail.php | 1 + 2 files changed, 27 insertions(+) diff --git a/app/Notifications/CheckoutConsumableNotification.php b/app/Notifications/CheckoutConsumableNotification.php index 376c70fdea..4b4fcc6ac6 100644 --- a/app/Notifications/CheckoutConsumableNotification.php +++ b/app/Notifications/CheckoutConsumableNotification.php @@ -9,6 +9,8 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; +use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; class CheckoutConsumableNotification extends Notification { @@ -43,6 +45,11 @@ class CheckoutConsumableNotification extends Notification { $notifyBy = []; + if (Setting::getSettings()->webhook_selected == 'microsoft'){ + + $notifyBy[] = MicrosoftTeamsChannel::class; + } + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -102,6 +109,25 @@ class CheckoutConsumableNotification extends Notification ->content($note); }); } + public function toMicrosoftTeams() + { + $target = $this->target; + $admin = $this->admin; + $item = $this->item; + $note = $this->note; + + return MicrosoftTeamsMessage::create() + ->to($this->settings->webhook_endpoint) + ->type('success') + ->addStartGroupToSection('activityTitle') + ->title("Consumable Checked Out") + ->addStartGroupToSection('activityText') + ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') + ->fact(trans('mail.Consumable_checkout_notification')." by ", $admin->present()->fullName()) + ->fact('Checked out to', $target->present()->fullName()) + ->fact('Number Remaining', $item->numRemaining()) + ->fact('Notes', $note ?: 'No notes'); + } /** * Get the mail representation of the notification. diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index a3632400c4..ca323c76c6 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -12,6 +12,7 @@ return [ 'Confirm_asset_delivery' => 'Asset delivery confirmation', 'Confirm_consumable_delivery' => 'Consumable delivery confirmation', 'Confirm_license_delivery' => 'License delivery confirmation', + 'Consumable_checkout_notification' => 'Consumable checked out', 'Days' => 'Days', 'Expected_Checkin_Date' => 'An asset checked out to you is due to be checked back in on :date', 'Expected_Checkin_Notification' => 'Reminder: :name checkin deadline approaching', From f270672a3d9219121930ea3ea68bdc5b8647f1c0 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 23 Jan 2024 13:05:39 -0800 Subject: [PATCH 10/13] 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); + + } } /** From 49021d277c708ed950e811ea8a9feb465fd82f18 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 23 Jan 2024 13:33:57 -0800 Subject: [PATCH 11/13] if not location add default location --- app/Notifications/CheckinAssetNotification.php | 2 +- app/Notifications/CheckoutAssetNotification.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 35fa3fdf9d..5af7c17fa6 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -102,7 +102,7 @@ class CheckinAssetNotification extends Notification ->title("Asset Checked in") ->addStartGroupToSection('activityText') ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText') - ->fact('Checked into ', $item->location->name ? $item->location->name : '') + ->fact('Checked into ', $item->location->name ? $item->location->name : $item->defaultLoc()->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/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index 29f1cc254b..6a890c0991 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -138,7 +138,7 @@ class CheckoutAssetNotification extends Notification ->title("Asset Checked Out") ->addStartGroupToSection('activityText') ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText') - ->fact('Checked out from ', $item->location ? $item->location->name : '') + ->fact('Checked out from ', $item->location ? $item->location->name : $item->assetLoc()->name) ->fact(trans('mail.Asset_Checkout_Notification') . " by ", $admin->present()->fullName()) ->fact('Asset Status', $item->assetstatus->name) ->fact('Notes', $note ?: 'No notes'); From 00f07ac2ce662d44e16548c4d1113d3a41b5f09c Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 24 Jan 2024 10:38:06 -0800 Subject: [PATCH 12/13] add translations, brush up code --- app/Http/Livewire/SlackSettingsForm.php | 6 ++--- .../CheckinAccessoryNotification.php | 15 ++++++----- .../CheckinAssetNotification.php | 13 +++++----- .../CheckinLicenseSeatNotification.php | 8 +++--- .../CheckoutAccessoryNotification.php | 26 ++++++++++--------- .../CheckoutAssetNotification.php | 25 +++++++----------- .../CheckoutConsumableNotification.php | 8 +++--- .../CheckoutLicenseSeatNotification.php | 8 +++--- resources/lang/en-US/admin/hardware/form.php | 1 + resources/lang/en-US/mail.php | 5 ++++ 10 files changed, 60 insertions(+), 55 deletions(-) diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index 3b1894fadc..9e811adca6 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -46,7 +46,7 @@ class SlackSettingsForm extends Component "general"=> array( "name" => trans('admin/settings/general.general_webhook'), "icon" => "fab fa-hashtag", - "placeholder" => "Insert URL", + "placeholder" => trans('general.url'), "link" => "", ), "microsoft" => array( @@ -193,8 +193,8 @@ class SlackSettingsForm extends Component [ "@type" => "MessageCard", "@context" => "http://schema.org/extensions", - "summary" => "Snipe-IT Integration Test Summary", - "title" => "Snipe-IT Integration Test", + "summary" => trans('mail.snipe_webhook_summary'), + "title" => trans('mail.snipe_webhook_test'), "text" => trans('general.webhook_test_msg', ['app' => $this->webhook_name]), ]; diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php index 3a36af7019..fbe525376e 100644 --- a/app/Notifications/CheckinAccessoryNotification.php +++ b/app/Notifications/CheckinAccessoryNotification.php @@ -37,11 +37,12 @@ class CheckinAccessoryNotification extends Notification */ public function via() { + $notifyBy = []; + if (Setting::getSettings()->webhook_selected == 'microsoft'){ - return [MicrosoftTeamsChannel::class]; - } - $notifyBy = []; + $notifyBy[] = MicrosoftTeamsChannel::class; + } if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; @@ -123,13 +124,13 @@ class CheckinAccessoryNotification extends Notification ->to($this->settings->webhook_endpoint) ->type('success') ->addStartGroupToSection('activityTitle') - ->title("Accessory Checked In") + ->title(trans('Accessory_Checkin_Notification')) ->addStartGroupToSection('activityText') ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') - ->fact('Checked into ', $item->location->name ? $item->location->name : '') + ->fact(trans('mail.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'); + ->fact(trans('admin/consumables/general.remaining'), $item->numRemaining()) + ->fact(trans('mail.notes'), $note ?: 'No notes'); } /** diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 5af7c17fa6..171b41831a 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -45,11 +45,12 @@ class CheckinAssetNotification extends Notification */ public function via() { + $notifyBy = []; + if (Setting::getSettings()->webhook_selected == 'microsoft'){ - return [MicrosoftTeamsChannel::class]; + $notifyBy[] = MicrosoftTeamsChannel::class; } - $notifyBy = []; if (Setting::getSettings()->webhook_endpoint != '') { \Log::debug('use webhook'); $notifyBy[] = 'slack'; @@ -99,13 +100,13 @@ class CheckinAssetNotification extends Notification return MicrosoftTeamsMessage::create() ->to($this->settings->webhook_endpoint) ->type('success') - ->title("Asset Checked in") + ->title(trans('mail.Asset_Checkin_Notification')) ->addStartGroupToSection('activityText') ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityText') - ->fact('Checked into ', $item->location->name ? $item->location->name : $item->defaultLoc()->name) + ->fact(trans('mail.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'); + ->fact(trans('admin/hardware/form.status'), $item->assetstatus->name) + ->fact(trans('mail.notes'), $note ?: trans('mail.no_notes')); } /** diff --git a/app/Notifications/CheckinLicenseSeatNotification.php b/app/Notifications/CheckinLicenseSeatNotification.php index d05f5ef6c1..2af301b7db 100644 --- a/app/Notifications/CheckinLicenseSeatNotification.php +++ b/app/Notifications/CheckinLicenseSeatNotification.php @@ -105,13 +105,13 @@ class CheckinLicenseSeatNotification extends Notification ->to($this->settings->webhook_endpoint) ->type('success') ->addStartGroupToSection('activityTitle') - ->title("License Checked in") + ->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('Checked in from', $target->present()->fullName()) - ->fact('Seats Remaining', $item->availCount()->count()) - ->fact('Notes', $note ?: 'No notes'); + ->fact(trans('mail.checkedin_from'), $target->present()->fullName()) + ->fact(trans('admin/consumables/general.remaining'), $item->availCount()->count()) + ->fact(trans('mail.notes'), $note ?: trans('mail.no_notes')); } /** diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php index a44c193b57..d0cb7d13d0 100644 --- a/app/Notifications/CheckoutAccessoryNotification.php +++ b/app/Notifications/CheckoutAccessoryNotification.php @@ -40,7 +40,6 @@ class CheckoutAccessoryNotification extends Notification if (Setting::getSettings()->webhook_selected == 'microsoft'){ -// return [MicrosoftTeamsChannel::class]; $notifyBy[] = MicrosoftTeamsChannel::class; } @@ -105,21 +104,24 @@ class CheckoutAccessoryNotification extends Notification } public function toMicrosoftTeams() { + $target = $this->target; $admin = $this->admin; $item = $this->item; $note = $this->note; - return MicrosoftTeamsMessage::create() - ->to($this->settings->webhook_endpoint) - ->type('success') - ->addStartGroupToSection('activityTitle') - ->title("Accessory Checked Out") - ->addStartGroupToSection('activityText') - ->fact(htmlspecialchars_decode($item->present()->name), '', 'activityTitle') - ->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'); + 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('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 ?: trans('mail.no_notes')); + } /** diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index 6a890c0991..652ec03f6a 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -126,27 +126,22 @@ class CheckoutAssetNotification extends Notification } public function toMicrosoftTeams() { + $target = $this->target; $admin = $this->admin; $item = $this->item; $note = $this->note; - try { + 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 ?: trans('mail.no_notes')); - 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 : $item->assetLoc()->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); - } } /** diff --git a/app/Notifications/CheckoutConsumableNotification.php b/app/Notifications/CheckoutConsumableNotification.php index 4b4fcc6ac6..c8cde7daf3 100644 --- a/app/Notifications/CheckoutConsumableNotification.php +++ b/app/Notifications/CheckoutConsumableNotification.php @@ -120,13 +120,13 @@ class CheckoutConsumableNotification extends Notification ->to($this->settings->webhook_endpoint) ->type('success') ->addStartGroupToSection('activityTitle') - ->title("Consumable Checked Out") + ->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('Checked out to', $target->present()->fullName()) - ->fact('Number Remaining', $item->numRemaining()) - ->fact('Notes', $note ?: 'No notes'); + ->fact(trans('mail.assigned_to'), $target->present()->fullName()) + ->fact(trans('admin/consumables/general.remaining'), $item->numRemaining()) + ->fact(trans('mail.notes'), $note ?: trans('mail.no_notes')); } /** diff --git a/app/Notifications/CheckoutLicenseSeatNotification.php b/app/Notifications/CheckoutLicenseSeatNotification.php index 9a7861444c..33db588350 100644 --- a/app/Notifications/CheckoutLicenseSeatNotification.php +++ b/app/Notifications/CheckoutLicenseSeatNotification.php @@ -121,13 +121,13 @@ class CheckoutLicenseSeatNotification extends Notification ->to($this->settings->webhook_endpoint) ->type('success') ->addStartGroupToSection('activityTitle') - ->title("License Checked Out") + ->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('Checked out to', $target->present()->fullName()) - ->fact('Seats Remaining', $item->availCount()->count()) - ->fact('Notes', $note ?: 'No notes'); + ->fact(trans('mail.assigned_to'), $target->present()->fullName()) + ->fact(trans('admin/consumables/general.remaining'), $item->availCount()->count()) + ->fact(trans('mail.notes'), $note ?: trans('mail.no_notes')); } /** diff --git a/resources/lang/en-US/admin/hardware/form.php b/resources/lang/en-US/admin/hardware/form.php index ee3fa20fb0..ae6b5646bd 100644 --- a/resources/lang/en-US/admin/hardware/form.php +++ b/resources/lang/en-US/admin/hardware/form.php @@ -35,6 +35,7 @@ return [ 'months' => 'months', 'name' => 'Asset Name', 'notes' => 'Notes', + 'no_notes' => 'No Notes', 'order' => 'Order Number', 'qr' => 'QR Code', 'requestable' => 'Users may request this asset', diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index ca323c76c6..418de5806f 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -41,6 +41,8 @@ return [ 'canceled' => 'Canceled:', 'checkin_date' => 'Checkin Date:', 'checkout_date' => 'Checkout Date:', + 'checkedout_from' => 'Checked out from', + 'checked_into' => 'Checked into', 'click_on_the_link_accessory' => 'Please click on the link at the bottom to confirm that you have received the accessory.', 'click_on_the_link_asset' => 'Please click on the link at the bottom to confirm that you have received the asset.', 'click_to_confirm' => 'Please click on the following link to confirm your :web account:', @@ -61,6 +63,7 @@ return [ 'min_QTY' => 'Min QTY', 'name' => 'Name', 'new_item_checked' => 'A new item has been checked out under your name, details are below.', + 'notes' => 'Notes', 'password' => 'Password:', 'password_reset' => 'Password Reset', 'read_the_terms' => 'Please read the terms of use below.', @@ -70,6 +73,8 @@ return [ 'reset_password' => 'Click here to reset your password:', 'rights_reserved' => 'All rights reserved.', 'serial' => 'Serial', + 'snipe_webhook_test' => 'Snipe-IT Integration Test', + 'snipe_webhook_summary' => 'Snipe-IT Integration Test Summary', 'supplier' => 'Supplier', 'tag' => 'Tag', 'test_email' => 'Test Email from Snipe-IT', From c65b32bcdb67420320d8bc3ca6e76fa0b7908847 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 24 Jan 2024 14:49:42 -0800 Subject: [PATCH 13/13] removed translation fixed via method --- app/Notifications/CheckinAccessoryNotification.php | 4 ++-- app/Notifications/CheckinAssetNotification.php | 4 ++-- app/Notifications/CheckinLicenseSeatNotification.php | 6 +++--- app/Notifications/CheckoutAccessoryNotification.php | 2 +- app/Notifications/CheckoutAssetNotification.php | 4 ++-- app/Notifications/CheckoutConsumableNotification.php | 4 ++-- app/Notifications/CheckoutLicenseSeatNotification.php | 4 ++-- resources/lang/en-US/admin/hardware/form.php | 1 - 8 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php index fbe525376e..f376c26a84 100644 --- a/app/Notifications/CheckinAccessoryNotification.php +++ b/app/Notifications/CheckinAccessoryNotification.php @@ -44,7 +44,7 @@ class CheckinAccessoryNotification extends Notification $notifyBy[] = MicrosoftTeamsChannel::class; } - if (Setting::getSettings()->webhook_endpoint != '') { + if (Setting::getSettings()->webhook_selected == 'slack') { $notifyBy[] = 'slack'; } @@ -130,7 +130,7 @@ class CheckinAccessoryNotification extends Notification ->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 ?: 'No notes'); + ->fact(trans('mail.notes'), $note ?: ''); } /** diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 171b41831a..8e9467c54f 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -51,7 +51,7 @@ class CheckinAssetNotification extends Notification $notifyBy[] = MicrosoftTeamsChannel::class; } - if (Setting::getSettings()->webhook_endpoint != '') { + if (Setting::getSettings()->webhook_selected == 'slack') { \Log::debug('use webhook'); $notifyBy[] = 'slack'; } @@ -106,7 +106,7 @@ class CheckinAssetNotification extends Notification ->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 ?: trans('mail.no_notes')); + ->fact(trans('mail.notes'), $note ?: ''); } /** diff --git a/app/Notifications/CheckinLicenseSeatNotification.php b/app/Notifications/CheckinLicenseSeatNotification.php index 2af301b7db..2222f937f3 100644 --- a/app/Notifications/CheckinLicenseSeatNotification.php +++ b/app/Notifications/CheckinLicenseSeatNotification.php @@ -48,7 +48,7 @@ class CheckinLicenseSeatNotification extends Notification $notifyBy[] = MicrosoftTeamsChannel::class; } - if (Setting::getSettings()->webhook_endpoint != '') { + if (Setting::getSettings()->webhook_selected == 'slack') { $notifyBy[] = 'slack'; } @@ -108,10 +108,10 @@ class CheckinLicenseSeatNotification extends Notification ->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.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 ?: trans('mail.no_notes')); + ->fact(trans('mail.notes'), $note ?: ''); } /** diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php index d0cb7d13d0..62fce8e176 100644 --- a/app/Notifications/CheckoutAccessoryNotification.php +++ b/app/Notifications/CheckoutAccessoryNotification.php @@ -120,7 +120,7 @@ class CheckoutAccessoryNotification extends Notification ->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 ?: trans('mail.no_notes')); + ->fact(trans('mail.notes'), $note ?: ''); } diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index 652ec03f6a..7350a7736b 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -60,7 +60,7 @@ class CheckoutAssetNotification extends Notification } $notifyBy = []; - if ((Setting::getSettings()) && (Setting::getSettings()->webhook_endpoint != '')) { + if ((Setting::getSettings()) && (Setting::getSettings()->webhook_selected == 'slack')) { \Log::debug('use webhook'); $notifyBy[] = 'slack'; } @@ -139,7 +139,7 @@ class CheckoutAssetNotification extends Notification ->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 ?: trans('mail.no_notes')); + ->fact(trans('mail.notes'), $note ?: ''); } diff --git a/app/Notifications/CheckoutConsumableNotification.php b/app/Notifications/CheckoutConsumableNotification.php index c8cde7daf3..228c4c2e95 100644 --- a/app/Notifications/CheckoutConsumableNotification.php +++ b/app/Notifications/CheckoutConsumableNotification.php @@ -50,7 +50,7 @@ class CheckoutConsumableNotification extends Notification $notifyBy[] = MicrosoftTeamsChannel::class; } - if (Setting::getSettings()->webhook_endpoint != '') { + if (Setting::getSettings()->webhook_selected == 'slack') { $notifyBy[] = 'slack'; } @@ -126,7 +126,7 @@ class CheckoutConsumableNotification extends Notification ->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 ?: trans('mail.no_notes')); + ->fact(trans('mail.notes'), $note ?: ''); } /** diff --git a/app/Notifications/CheckoutLicenseSeatNotification.php b/app/Notifications/CheckoutLicenseSeatNotification.php index 33db588350..d5c9871f3b 100644 --- a/app/Notifications/CheckoutLicenseSeatNotification.php +++ b/app/Notifications/CheckoutLicenseSeatNotification.php @@ -51,7 +51,7 @@ class CheckoutLicenseSeatNotification extends Notification $notifyBy[] = MicrosoftTeamsChannel::class; } - if (Setting::getSettings()->webhook_endpoint != '') { + if (Setting::getSettings()->webhook_selected == 'slack') { $notifyBy[] = 'slack'; } @@ -127,7 +127,7 @@ class CheckoutLicenseSeatNotification extends Notification ->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 ?: trans('mail.no_notes')); + ->fact(trans('mail.notes'), $note ?: ''); } /** diff --git a/resources/lang/en-US/admin/hardware/form.php b/resources/lang/en-US/admin/hardware/form.php index ae6b5646bd..ee3fa20fb0 100644 --- a/resources/lang/en-US/admin/hardware/form.php +++ b/resources/lang/en-US/admin/hardware/form.php @@ -35,7 +35,6 @@ return [ 'months' => 'months', 'name' => 'Asset Name', 'notes' => 'Notes', - 'no_notes' => 'No Notes', 'order' => 'Order Number', 'qr' => 'QR Code', 'requestable' => 'Users may request this asset',