A free open source IT asset/license management system
refactor Checkin Notifications to accept company integration settings
Godfrey M13173efc4a87
diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.phpindex e158a53990..0197297b30 100644--- a/app/Notifications/CheckinAccessoryNotification.php+++ b/app/Notifications/CheckinAccessoryNotification.php@@ -3,6 +3,7 @@namespace App\Notifications;use App\Models\Accessory;+use App\Models\Company;use App\Models\Setting;use App\Models\User;use Illuminate\Bus\Queueable;@@ -32,7 +33,8 @@ class CheckinAccessoryNotification extends Notification implements ShouldQueuepublic Accessory $item,public $target,public User $admin,- public $note+ public $note,+ public Company|Setting $webhookSource,) {}/**@@ -43,17 +45,17 @@ class CheckinAccessoryNotification extends Notification implements ShouldQueuepublic function via(){$notifyBy = [];- if (Setting::getSettings()->webhook_selected == 'google' && Setting::getSettings()->webhook_endpoint) {+ if ($this->webhookSource->webhook_selected == 'google' && $this->webhookSource->webhook_endpoint) {$notifyBy[] = GoogleChatChannel::class;}- if (Setting::getSettings()->webhook_selected == 'microsoft' && Setting::getSettings()->webhook_endpoint) {+ if ($this->webhookSource->webhook_selected == 'microsoft' && $this->webhookSource->webhook_endpoint) {$notifyBy[] = MicrosoftTeamsChannel::class;}- if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general') {+ if ($this->webhookSource->webhook_selected == 'slack' || $this->webhookSource->webhook_selected == 'general') {$notifyBy[] = SlackWebhookChannel::class;}@@ -66,8 +68,8 @@ class CheckinAccessoryNotification extends Notification implements ShouldQueue$admin = $this->admin;$item = $this->item;$note = $this->note;- $botname = (Setting::getSettings()->webhook_botname) ? Setting::getSettings()->webhook_botname : 'Snipe-Bot';- $channel = (Setting::getSettings()->webhook_channel) ? Setting::getSettings()->webhook_channel : '';+ $botname = ($this->webhookSource->webhook_botname) ? $this->webhookSource->webhook_botname : 'Snipe-Bot';+ $channel = ($this->webhookSource->webhook_channel) ? $this->webhookSource->webhook_channel : '';$fields = [trans('general.from') => '<'.$target->present()->viewUrl().'|'.$target->display_name.'>',@@ -98,9 +100,9 @@ class CheckinAccessoryNotification extends Notification implements ShouldQueue$admin = $this->admin;$item = $this->item;$note = $this->note;- if (! Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {+ if (!Str::contains($this->webhookSource->webhook_endpoint, 'workflows')) {return MicrosoftTeamsMessage::create()- ->to(Setting::getSettings()->webhook_endpoint)+ ->to($this->webhookSource->webhook_endpoint)->type('success')->addStartGroupToSection('activityTitle')->title(trans('Accessory_Checkin_Notification'))@@ -130,7 +132,7 @@ class CheckinAccessoryNotification extends Notification implements ShouldQueue$note = $this->note;return GoogleChatMessage::create()- ->to(Setting::getSettings()->webhook_endpoint)+ ->to($this->webhookSource->webhook_endpoint)->card(Card::create()->header(diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.phpindex 4bdb921910..73e6a39481 100644--- a/app/Notifications/CheckinAssetNotification.php+++ b/app/Notifications/CheckinAssetNotification.php@@ -4,6 +4,7 @@ namespace App\Notifications;use App\Helpers\Helper;use App\Models\Asset;+use App\Models\Company;use App\Models\Setting;use App\Models\User;use Illuminate\Bus\Queueable;@@ -35,7 +36,8 @@ class CheckinAssetNotification extends Notification implements ShouldQueuepublic Asset $item,public $target,public User $admin,- public $note+ public $note,+ public Company|Setting $webhookSource,){if ($this->item->expected_checkin) {@@ -51,16 +53,16 @@ class CheckinAssetNotification extends Notification implements ShouldQueue*/public function via(){- if (Setting::getSettings()->webhook_selected == 'google' && Setting::getSettings()->webhook_endpoint) {+ if ($this->webhookSource->webhook_selected == 'google' && $this->webhookSource->webhook_endpoint) {$notifyBy[] = GoogleChatChannel::class;}- if (Setting::getSettings()->webhook_selected == 'microsoft' && Setting::getSettings()->webhook_endpoint) {+ if ($this->webhookSource->webhook_selected == 'microsoft' && $this->webhookSource->webhook_endpoint) {$notifyBy[] = MicrosoftTeamsChannel::class;}- if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general') {+ if ($this->webhookSource->webhook_selected == 'slack' || $this->webhookSource->webhook_selected == 'general') {Log::debug('use webhook');$notifyBy[] = SlackWebhookChannel::class;}@@ -73,8 +75,8 @@ class CheckinAssetNotification extends Notification implements ShouldQueue$admin = $this->admin;$item = $this->item;$note = $this->note;- $botname = (Setting::getSettings()->webhook_botname != '') ? Setting::getSettings()->webhook_botname : 'Snipe-Bot';- $channel = (Setting::getSettings()->webhook_channel) ? Setting::getSettings()->webhook_channel : '';+ $botname = ($this->webhookSource->webhook_botname != '') ? $this->webhookSource->webhook_botname : 'Snipe-Bot';+ $channel = ($this->webhookSource->webhook_channel) ? $this->webhookSource->webhook_channel : '';$fields = [trans('general.administrator') => '<'.$admin->present()->viewUrl().'|'.$admin->display_name.'>',@@ -107,9 +109,9 @@ class CheckinAssetNotification extends Notification implements ShouldQueue$item = $this->item;$note = $this->note;- if (! Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {+ if (!Str::contains($this->webhookSource->webhook_endpoint, 'workflows')) {return MicrosoftTeamsMessage::create()- ->to(Setting::getSettings()->webhook_endpoint)+ ->to($this->webhookSource->webhook_endpoint)->type('success')->title(trans('mail.Asset_Checkin_Notification', ['tag' => '']))->addStartGroupToSection('activityText')@@ -140,7 +142,7 @@ class CheckinAssetNotification extends Notification implements ShouldQueue//return GoogleChatMessage::create()- ->to(Setting::getSettings()->webhook_endpoint)+ ->to($this->webhookSource->webhook_endpoint)->card(Card::create()->header(diff --git a/app/Notifications/CheckinComponentNotification.php b/app/Notifications/CheckinComponentNotification.phpindex e8106365ff..87d2e8824c 100644--- a/app/Notifications/CheckinComponentNotification.php+++ b/app/Notifications/CheckinComponentNotification.php@@ -2,6 +2,7 @@namespace App\Notifications;+use App\Models\Company;use App\Models\Component;use App\Models\Setting;use App\Models\User;@@ -34,7 +35,8 @@ class CheckinComponentNotification extends Notification implements ShouldQueuepublic Component $item,public $target,public User $admin,- public $note+ public $note,+ public Company|Setting $webhookSource,){}@@ -48,16 +50,16 @@ class CheckinComponentNotification extends Notification implements ShouldQueue{$notifyBy = [];- if (Setting::getSettings()->webhook_selected == 'google' && Setting::getSettings()->webhook_endpoint) {+ if ($this->webhookSource->webhook_selected == 'google' && $this->webhookSource->webhook_endpoint) {$notifyBy[] = GoogleChatChannel::class;}- if (Setting::getSettings()->webhook_selected == 'microsoft' && Setting::getSettings()->webhook_endpoint) {+ if ($this->webhookSource->webhook_selected == 'microsoft' && $this->webhookSource->webhook_endpoint) {$notifyBy[] = MicrosoftTeamsChannel::class;}- if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general') {+ if ($this->webhookSource->webhook_selected == 'slack' || $this->webhookSource->webhook_selected == 'general') {$notifyBy[] = SlackWebhookChannel::class;}@@ -70,8 +72,8 @@ class CheckinComponentNotification extends Notification implements ShouldQueue$admin = $this->admin;$item = $this->item;$note = $this->note;- $botname = (Setting::getSettings()->webhook_botname) ? Setting::getSettings()->webhook_botname : 'Snipe-Bot';- $channel = (Setting::getSettings()->webhook_channel) ? Setting::getSettings()->webhook_channel : '';+ $botname = ($this->webhookSource->webhook_botname) ? $this->webhookSource->webhook_botname : 'Snipe-Bot';+ $channel = ($this->webhookSource->webhook_channel) ? $this->webhookSource->webhook_channel : '';if ($admin) {$fields = [@@ -111,9 +113,9 @@ class CheckinComponentNotification extends Notification implements ShouldQueue$admin = $this->admin;$item = $this->item;$note = $this->note;- if (! Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {+ if (!Str::contains($this->webhookSource->webhook_endpoint, 'workflows')) {return MicrosoftTeamsMessage::create()- ->to(Setting::getSettings()->webhook_endpoint)+ ->to($this->webhookSource->webhook_endpoint)->type('success')->addStartGroupToSection('activityTitle')->title(trans('mail.Component_checkin_notification'))@@ -143,7 +145,7 @@ class CheckinComponentNotification extends Notification implements ShouldQueue$note = $this->note;return GoogleChatMessage::create()- ->to(Setting::getSettings()->webhook_endpoint)+ ->to($this->webhookSource->webhook_endpoint)->card(Card::create()->header(diff --git a/app/Notifications/CheckinLicenseSeatNotification.php b/app/Notifications/CheckinLicenseSeatNotification.phpindex 1457ddfc43..4b11720221 100644--- a/app/Notifications/CheckinLicenseSeatNotification.php+++ b/app/Notifications/CheckinLicenseSeatNotification.php@@ -2,6 +2,7 @@namespace App\Notifications;+use App\Models\Company;use App\Models\License;use App\Models\LicenseSeat;use App\Models\Setting;@@ -34,7 +35,7 @@ class CheckinLicenseSeatNotification extends Notification implements ShouldQueue** @param $params*/- public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedInBy, $note)+ public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedInBy, $note, public Company|Setting $webhookSource){$this->target = $checkedOutTo;$this->item = $licenseSeat->license; // *This* is the thing preventing us from doing the constructor-promotion thing :(@@ -51,16 +52,16 @@ class CheckinLicenseSeatNotification extends Notification implements ShouldQueue{$notifyBy = [];- if (Setting::getSettings()->webhook_selected == 'google' && Setting::getSettings()->webhook_endpoint) {+ if ($this->webhookSource->webhook_selected == 'google' && $this->webhookSource->webhook_endpoint) {$notifyBy[] = GoogleChatChannel::class;}- if (Setting::getSettings()->webhook_selected == 'microsoft' && Setting::getSettings()->webhook_endpoint) {+ if ($this->webhookSource->webhook_selected == 'microsoft' && $this->webhookSource->webhook_endpoint) {$notifyBy[] = MicrosoftTeamsChannel::class;}- if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general') {+ if ($this->webhookSource->webhook_selected == 'slack' || $this->webhookSource->webhook_selected == 'general') {$notifyBy[] = SlackWebhookChannel::class;}@@ -73,8 +74,8 @@ class CheckinLicenseSeatNotification extends Notification implements ShouldQueue$admin = $this->admin;$item = $this->item;$note = $this->note;- $botname = (Setting::getSettings()->webhook_botname) ? Setting::getSettings()->webhook_botname : 'Snipe-Bot';- $channel = (Setting::getSettings()->webhook_channel) ? Setting::getSettings()->webhook_channel : '';+ $botname = ($this->webhookSource->webhook_botname) ? $this->webhookSource->webhook_botname : 'Snipe-Bot';+ $channel = ($this->webhookSource->webhook_channel) ? $this->webhookSource->webhook_channel : '';if ($admin) {$fields = [@@ -114,9 +115,9 @@ class CheckinLicenseSeatNotification extends Notification implements ShouldQueue$admin = $this->admin;$item = $this->item;$note = $this->note;- if (! Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {+ if (!Str::contains($this->webhookSource->webhook_endpoint, 'workflows')) {return MicrosoftTeamsMessage::create()- ->to(Setting::getSettings()->webhook_endpoint)+ ->to($this->webhookSource->webhook_endpoint)->type('success')->addStartGroupToSection('activityTitle')->title(trans('mail.License_Checkin_Notification'))@@ -147,7 +148,7 @@ class CheckinLicenseSeatNotification extends Notification implements ShouldQueue$note = $this->note;return GoogleChatMessage::create()- ->to(Setting::getSettings()->webhook_endpoint)+ ->to($this->webhookSource->webhook_endpoint)->card(Card::create()->header(diff --git a/app/Notifications/CheckoutComponentNotification.php b/app/Notifications/CheckoutComponentNotification.phpindex 78ef2ca7ca..4c2792ec14 100644--- a/app/Notifications/CheckoutComponentNotification.php+++ b/app/Notifications/CheckoutComponentNotification.php@@ -36,7 +36,7 @@ class CheckoutComponentNotification extends Notification implements ShouldQueuepublic $target,public User $admin,public $acceptance,- public $note,+ public $note,public Company|Setting $webhookSource,){