From fe6295a5e43da2fbc7730128bd0baba0952d9ba0 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 22 Mar 2023 14:43:00 -0700 Subject: [PATCH 1/2] Update slack_* properties to webhook_* --- app/Models/Setting.php | 8 ++++---- app/Models/User.php | 2 +- app/Notifications/AuditNotification.php | 2 +- app/Notifications/CheckinAccessoryNotification.php | 8 ++------ app/Notifications/CheckinAssetNotification.php | 7 +++---- app/Notifications/CheckinLicenseSeatNotification.php | 4 ++-- app/Notifications/CheckoutAccessoryNotification.php | 4 ++-- app/Notifications/CheckoutAssetNotification.php | 6 +++--- app/Notifications/CheckoutConsumableNotification.php | 4 ++-- app/Notifications/CheckoutLicenseSeatNotification.php | 4 ++-- app/Notifications/RequestAssetCancelation.php | 6 +++--- app/Notifications/RequestAssetNotification.php | 4 ++-- resources/views/accessories/checkout.blade.php | 6 +++--- resources/views/consumables/checkout.blade.php | 6 +++--- resources/views/hardware/checkout.blade.php | 6 +++--- resources/views/licenses/checkout.blade.php | 6 +++--- 16 files changed, 39 insertions(+), 44 deletions(-) diff --git a/app/Models/Setting.php b/app/Models/Setting.php index fd02992f7..ecac18335 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -83,9 +83,9 @@ class Setting extends Model 'email_domain', 'email_format', 'username_format', - 'slack_endpoint', - 'slack_channel', - 'slack_botname', + 'webhook_endpoint', + 'webhook_channel', + 'webhook_botname', ]; /** @@ -265,7 +265,7 @@ class Setting extends Model { // At this point the endpoint is the same for everything. // In the future this may want to be adapted for individual notifications. - return self::getSettings()->slack_endpoint; + return self::getSettings()->webhook_endpoint; } /** diff --git a/app/Models/User.php b/app/Models/User.php index 0e9d839a5..bf40982db 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -272,7 +272,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo { // At this point the endpoint is the same for everything. // In the future this may want to be adapted for individual notifications. - $this->endpoint = \App\Models\Setting::getSettings()->slack_endpoint; + $this->endpoint = \App\Models\Setting::getSettings()->webhook_endpoint; return $this->endpoint; } diff --git a/app/Notifications/AuditNotification.php b/app/Notifications/AuditNotification.php index 84f175376..9f5ae9668 100644 --- a/app/Notifications/AuditNotification.php +++ b/app/Notifications/AuditNotification.php @@ -34,7 +34,7 @@ class AuditNotification extends Notification public function via() { $notifyBy = []; - if (Setting::getSettings()->slack_endpoint) { + if (Setting::getSettings()->webhook_endpoint) { $notifyBy[] = 'slack'; } diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php index f9abba59f..a375f37ad 100644 --- a/app/Notifications/CheckinAccessoryNotification.php +++ b/app/Notifications/CheckinAccessoryNotification.php @@ -39,11 +39,7 @@ class CheckinAccessoryNotification extends Notification \Log::debug('via called'); $notifyBy = []; - if (Setting::getSettings()->slack_endpoint) { - $notifyBy[] = 'slack'; - } - - if (Setting::getSettings()->slack_endpoint != '') { + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -95,7 +91,7 @@ class CheckinAccessoryNotification extends Notification $admin = $this->admin; $item = $this->item; $note = $this->note; - $botname = ($this->settings->slack_botname) ? $this->settings->slack_botname : 'Snipe-Bot'; + $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $fields = [ 'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>', diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 9868ad1b4..e8fdcf678 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -43,9 +43,8 @@ class CheckinAssetNotification extends Notification public function via() { $notifyBy = []; - - if (Setting::getSettings()->slack_endpoint != '') { - \Log::debug('use slack'); + if (Setting::getSettings()->webhook_endpoint != '') { + \Log::debug('use webhook'); $notifyBy[] = 'slack'; } @@ -65,7 +64,7 @@ class CheckinAssetNotification extends Notification $admin = $this->admin; $item = $this->item; $note = $this->note; - $botname = ($this->settings->slack_botname != '') ? $this->settings->slack_botname : 'Snipe-Bot'; + $botname = ($this->settings->webhook_botname != '') ? $this->settings->webhook_botname : 'Snipe-Bot'; $fields = [ trans('general.administrator') => '<'.$admin->present()->viewUrl().'|'.$admin->present()->fullName().'>', diff --git a/app/Notifications/CheckinLicenseSeatNotification.php b/app/Notifications/CheckinLicenseSeatNotification.php index faeafecb1..a68930a68 100644 --- a/app/Notifications/CheckinLicenseSeatNotification.php +++ b/app/Notifications/CheckinLicenseSeatNotification.php @@ -41,7 +41,7 @@ class CheckinLicenseSeatNotification extends Notification { $notifyBy = []; - if (Setting::getSettings()->slack_endpoint != '') { + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -62,7 +62,7 @@ class CheckinLicenseSeatNotification extends Notification $admin = $this->admin; $item = $this->item; $note = $this->note; - $botname = ($this->settings->slack_botname) ? $this->settings->slack_botname : 'Snipe-Bot'; + $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; if ($admin) { $fields = [ diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php index 5882fdf27..982fd863c 100644 --- a/app/Notifications/CheckoutAccessoryNotification.php +++ b/app/Notifications/CheckoutAccessoryNotification.php @@ -37,7 +37,7 @@ class CheckoutAccessoryNotification extends Notification { $notifyBy = []; - if (Setting::getSettings()->slack_endpoint != '') { + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -78,7 +78,7 @@ class CheckoutAccessoryNotification extends Notification $admin = $this->admin; $item = $this->item; $note = $this->note; - $botname = ($this->settings->slack_botname) ? $this->settings->slack_botname : 'Snipe-Bot'; + $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $fields = [ 'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>', diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index c56c1a371..303fc08f1 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -53,8 +53,8 @@ class CheckoutAssetNotification extends Notification { $notifyBy = []; - if ((Setting::getSettings()) && (Setting::getSettings()->slack_endpoint != '')) { - \Log::debug('use slack'); + if ((Setting::getSettings()) && (Setting::getSettings()->webhook_endpoint != '')) { + \Log::debug('use webhook'); $notifyBy[] = 'slack'; } @@ -95,7 +95,7 @@ class CheckoutAssetNotification extends Notification $admin = $this->admin; $item = $this->item; $note = $this->note; - $botname = ($this->settings->slack_botname) ? $this->settings->slack_botname : 'Snipe-Bot'; + $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $fields = [ 'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>', diff --git a/app/Notifications/CheckoutConsumableNotification.php b/app/Notifications/CheckoutConsumableNotification.php index bfebe2c7d..84e52fea7 100644 --- a/app/Notifications/CheckoutConsumableNotification.php +++ b/app/Notifications/CheckoutConsumableNotification.php @@ -43,7 +43,7 @@ class CheckoutConsumableNotification extends Notification { $notifyBy = []; - if (Setting::getSettings()->slack_endpoint != '') { + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -84,7 +84,7 @@ class CheckoutConsumableNotification extends Notification $admin = $this->admin; $item = $this->item; $note = $this->note; - $botname = ($this->settings->slack_botname) ? $this->settings->slack_botname : 'Snipe-Bot'; + $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $fields = [ 'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>', diff --git a/app/Notifications/CheckoutLicenseSeatNotification.php b/app/Notifications/CheckoutLicenseSeatNotification.php index 50d8313c0..d4741d9be 100644 --- a/app/Notifications/CheckoutLicenseSeatNotification.php +++ b/app/Notifications/CheckoutLicenseSeatNotification.php @@ -43,7 +43,7 @@ class CheckoutLicenseSeatNotification extends Notification { $notifyBy = []; - if (Setting::getSettings()->slack_endpoint != '') { + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -84,7 +84,7 @@ class CheckoutLicenseSeatNotification extends Notification $admin = $this->admin; $item = $this->item; $note = $this->note; - $botname = ($this->settings->slack_botname) ? $this->settings->slack_botname : 'Snipe-Bot'; + $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $fields = [ 'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>', diff --git a/app/Notifications/RequestAssetCancelation.php b/app/Notifications/RequestAssetCancelation.php index ea76056af..905900de0 100644 --- a/app/Notifications/RequestAssetCancelation.php +++ b/app/Notifications/RequestAssetCancelation.php @@ -57,8 +57,8 @@ class RequestAssetCancelation extends Notification { $notifyBy = []; - if (Setting::getSettings()->slack_endpoint != '') { - \Log::debug('use slack'); + if (Setting::getSettings()->webhook_endpoint != '') { + \Log::debug('use webhook'); $notifyBy[] = 'slack'; } @@ -73,7 +73,7 @@ class RequestAssetCancelation extends Notification $item = $this->item; $note = $this->note; $qty = $this->item_quantity; - $botname = ($this->settings->slack_botname) ? $this->settings->slack_botname : 'Snipe-Bot'; + $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $fields = [ 'QTY' => $qty, diff --git a/app/Notifications/RequestAssetNotification.php b/app/Notifications/RequestAssetNotification.php index 22a8f3d46..028719f16 100644 --- a/app/Notifications/RequestAssetNotification.php +++ b/app/Notifications/RequestAssetNotification.php @@ -58,7 +58,7 @@ class RequestAssetNotification extends Notification { $notifyBy = []; - if (Setting::getSettings()->slack_endpoint != '') { + if (Setting::getSettings()->webhook_endpoint != '') { $notifyBy[] = 'slack'; } @@ -73,7 +73,7 @@ class RequestAssetNotification extends Notification $qty = $this->item_quantity; $item = $this->item; $note = $this->note; - $botname = ($this->settings->slack_botname) ? $this->settings->slack_botname : 'Snipe-Bot'; + $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot'; $fields = [ 'QTY' => $qty, diff --git a/resources/views/accessories/checkout.blade.php b/resources/views/accessories/checkout.blade.php index 000df2652..3463d5eff 100755 --- a/resources/views/accessories/checkout.blade.php +++ b/resources/views/accessories/checkout.blade.php @@ -54,7 +54,7 @@ @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.select_user'), 'fieldname' => 'assigned_to']) - @if ($accessory->requireAcceptance() || $accessory->getEula() || ($snipeSettings->slack_endpoint!='')) + @if ($accessory->requireAcceptance() || $accessory->getEula() || ($snipeSettings->webhook_endpoint!=''))
@@ -71,9 +71,9 @@
@endif - @if ($snipeSettings->slack_endpoint!='') + @if ($snipeSettings->webhook_endpoint!='') - A slack message will be sent + {{ trans('general.webhook_msg_note') }} @endif
diff --git a/resources/views/consumables/checkout.blade.php b/resources/views/consumables/checkout.blade.php index 85cec320e..bc17e893a 100644 --- a/resources/views/consumables/checkout.blade.php +++ b/resources/views/consumables/checkout.blade.php @@ -41,7 +41,7 @@ @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.select_user'), 'fieldname' => 'assigned_to', 'required'=> 'true']) - @if ($consumable->requireAcceptance() || $consumable->getEula() || ($snipeSettings->slack_endpoint!='')) + @if ($consumable->requireAcceptance() || $consumable->getEula() || ($snipeSettings->webhook_endpoint!=''))
@@ -58,9 +58,9 @@
@endif - @if ($snipeSettings->slack_endpoint!='') + @if ($snipeSettings->webhook_endpoint!='') - {{ trans('general.slack_msg_note') }} + {{ trans('general.webhook_msg_note') }} @endif
diff --git a/resources/views/hardware/checkout.blade.php b/resources/views/hardware/checkout.blade.php index 98536c80f..9f91dace1 100755 --- a/resources/views/hardware/checkout.blade.php +++ b/resources/views/hardware/checkout.blade.php @@ -114,7 +114,7 @@
- @if ($asset->requireAcceptance() || $asset->getEula() || ($snipeSettings->slack_endpoint!='')) + @if ($asset->requireAcceptance() || $asset->getEula() || ($snipeSettings->webhook_endpoint!=''))
@@ -131,9 +131,9 @@
@endif - @if ($snipeSettings->slack_endpoint!='') + @if ($snipeSettings->webhook_endpoint!='') - {{ trans('general.slack_msg_note')}} + {{ trans('general.webhook_msg_note') }} @endif
diff --git a/resources/views/licenses/checkout.blade.php b/resources/views/licenses/checkout.blade.php index 77e58e2fd..4d41d8c03 100755 --- a/resources/views/licenses/checkout.blade.php +++ b/resources/views/licenses/checkout.blade.php @@ -65,7 +65,7 @@
- @if ($license->requireAcceptance() || $license->getEula() || ($snipeSettings->slack_endpoint!='')) + @if ($license->requireAcceptance() || $license->getEula() || ($snipeSettings->webhook_endpoint!=''))
@@ -88,9 +88,9 @@
@endif - @if ($snipeSettings->slack_endpoint!='') + @if ($snipeSettings->webhook_endpoint!='') - {{ trans('general.slack_msg_note') }} + {{ trans('general.webhook_msg_note') }} @endif
From 9d2c4a4dee646f42f5e92b8f0b89e9fa30410297 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 23 Mar 2023 10:38:35 -0700 Subject: [PATCH 2/2] Update webhook message --- resources/lang/en/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index ad96a2bb7..1ad9c376d 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -253,7 +253,7 @@ return [ 'signature' => 'Signature', 'signed_off_by' => 'Signed Off By', 'skin' => 'Skin', - 'webhook_msg_note' => 'A :app message will be sent', + 'webhook_msg_note' => 'A notification will be sent via webhook', 'webhook_test_msg' => 'Oh hai! Looks like your :app integration with Snipe-IT is working!', 'some_features_disabled' => 'DEMO MODE: Some features are disabled for this installation.', 'site_name' => 'Site Name',