Skip to content

A free open source IT asset/license management system

checked in notification fires, updated icon translation usage

Godfrey M36090bf83e7e
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index 1767d70bbe..a00cfd00d7 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -22,6 +22,7 @@ use App\Models\Setting;
use App\Models\User;
use App\Notifications\CheckinAccessoryNotification;
use App\Notifications\CheckinAssetNotification;
+use App\Notifications\CheckinComponentNotification;
use App\Notifications\CheckinLicenseSeatNotification;
use App\Notifications\CheckoutAccessoryNotification;
use App\Notifications\CheckoutAssetNotification;
@@ -270,9 +271,9 @@ class CheckoutableListener
case LicenseSeat::class:
$notificationClass = CheckinLicenseSeatNotification::class;
break;
-// case Component::class:
-// $notificationClass = CheckinComponentNotification::class;
-// break;
+ case Component::class:
+ $notificationClass = CheckinComponentNotification::class;
+ break;
}
Log::debug('Notification class: '.$notificationClass);
diff --git a/app/Notifications/CheckinComponentNotification.php b/app/Notifications/CheckinComponentNotification.php
new file mode 100644
index 0000000000..0786b52178
--- /dev/null
+++ b/app/Notifications/CheckinComponentNotification.php
@@ -0,0 +1,166 @@
+<?php
+
+namespace App\Notifications;
+
+use App\Models\Component;
+use App\Models\Setting;
+use App\Models\User;
+use Illuminate\Bus\Queueable;
+use Illuminate\Notifications\Channels\SlackWebhookChannel;
+use Illuminate\Notifications\Messages\SlackMessage;
+use Illuminate\Notifications\Notification;
+use Illuminate\Support\Str;
+use NotificationChannels\GoogleChat\Card;
+use NotificationChannels\GoogleChat\GoogleChatChannel;
+use NotificationChannels\GoogleChat\GoogleChatMessage;
+use NotificationChannels\GoogleChat\Section;
+use NotificationChannels\GoogleChat\Widgets\KeyValue;
+use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel;
+use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage;
+
+class CheckinComponentNotification extends Notification
+{
+ use Queueable;
+ /**
+ * @var
+ */
+ private $params;
+
+ /**
+ * Create a new notification instance.
+ *
+ * @param $params
+ */
+ public function __construct(Component $component, $checkedOutTo, User $checkedInBy, $note)
+ {
+ $this->target = $checkedOutTo;
+ $this->item = $component;
+ $this->admin = $checkedInBy;
+ $this->note = $note;
+ $this->settings = Setting::getSettings();
+ }
+
+ /**
+ * Get the notification's delivery channels.
+ *
+ * @return array
+ */
+ public function via()
+ {
+ $notifyBy = [];
+
+ if (Setting::getSettings()->webhook_selected == 'google' && Setting::getSettings()->webhook_endpoint) {
+
+ $notifyBy[] = GoogleChatChannel::class;
+ }
+ if (Setting::getSettings()->webhook_selected == 'microsoft' && Setting::getSettings()->webhook_endpoint) {
+
+ $notifyBy[] = MicrosoftTeamsChannel::class;
+ }
+
+ if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general' ) {
+ $notifyBy[] = SlackWebhookChannel::class;
+ }
+
+ return $notifyBy;
+ }
+
+ public function toSlack()
+ {
+ $target = $this->target;
+ $admin = $this->admin;
+ $item = $this->item;
+ $note = $this->note;
+ $botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot';
+ $channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
+
+ if ($admin) {
+ $fields = [
+ trans('general.from') => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
+ trans('general.by') => '<'.$admin->present()->viewUrl().'|'.$admin->present()->fullName().'>',
+ ];
+
+ if ($item->location) {
+ $fields[trans('general.location')] = $item->location->name;
+ }
+
+ if ($item->company) {
+ $fields[trans('general.company')] = $item->company->name;
+ }
+
+ } else {
+ $fields = [
+ 'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
+ 'By' => 'CLI tool',
+ ];
+ }
+
+ return (new SlackMessage)
+ ->content(':arrow_down: :package: '.trans('mail.Component_checkin_notification'))
+ ->from($botname)
+ ->to($channel)
+ ->attachment(function ($attachment) use ($item, $note, $admin, $fields) {
+ $attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
+ ->fields($fields)
+ ->content($note);
+ });
+ }
+ public function toMicrosoftTeams()
+ {
+ $target = $this->target;
+ $admin = $this->admin;
+ $item = $this->item;
+ $note = $this->note;
+ if(!Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {
+ return MicrosoftTeamsMessage::create()
+ ->to($this->settings->webhook_endpoint)
+ ->type('success')
+ ->addStartGroupToSection('activityTitle')
+ ->title(trans('mail.Component_checkin_notification'))
+ ->addStartGroupToSection('activityText')
+ ->fact(htmlspecialchars_decode($item->present()->name), '', 'header')
+ ->fact(trans('mail.Component_checkin_notification')." by ", $admin->present()->fullName() ?: 'CLI tool')
+ ->fact(trans('mail.checkedin_from'), $target->present()->fullName())
+ ->fact(trans('admin/consumables/general.remaining'), $item->availCount()->count())
+ ->fact(trans('mail.notes'), $note ?: '');
+ }
+
+ $message = trans('mail.Component_checkin_notification');
+ $details = [
+ trans('mail.checkedin_from')=> $target->present()->fullName(),
+ trans('mail.license_for') => htmlspecialchars_decode($item->present()->name),
+ trans('mail.Component_checkin_notification')." by " => $admin->present()->fullName() ?: 'CLI tool',
+ trans('admin/consumables/general.remaining') => $item->availCount()->count(),
+ trans('mail.notes') => $note ?: '',
+ ];
+
+ return array($message, $details);
+ }
+ public function toGoogleChat()
+ {
+ $target = $this->target;
+ $item = $this->item;
+ $note = $this->note;
+
+ return GoogleChatMessage::create()
+ ->to($this->settings->webhook_endpoint)
+ ->card(
+ Card::create()
+ ->header(
+ '<strong>'.trans('mail.Component_checkin_notification').'</strong>' ?: '',
+ htmlspecialchars_decode($item->present()->name) ?: '',
+ )
+ ->section(
+ Section::create(
+ KeyValue::create(
+ trans('mail.checkedin_from') ?: '',
+ $target->present()->fullName() ?: '',
+ trans('admin/consumables/general.remaining').': '.$item->availCount()->count(),
+ )
+ ->onClick(route('components.show', $item->id))
+ )
+ )
+ );
+
+ }
+}
diff --git a/app/Notifications/CheckoutComponentNotification.php b/app/Notifications/CheckoutComponentNotification.php
index 8b4a950f98..fab303fb52 100644
--- a/app/Notifications/CheckoutComponentNotification.php
+++ b/app/Notifications/CheckoutComponentNotification.php
@@ -93,7 +93,7 @@ class CheckoutComponentNotification extends Notification
}
return (new SlackMessage)
- ->content(':arrow_up: :paperclip: Component Checked Out')
+ ->content(':arrow_up: :package: '.trans('mail.Component_checkout_notification'))
->from($botname)
->to($channel)
->attachment(function ($attachment) use ($item, $note, $admin, $fields) {
@@ -155,7 +155,7 @@ class CheckoutComponentNotification extends Notification
$target->present()->fullName() ?: '',
trans('admin/consumables/general.remaining').': '.$item->numRemaining(),
)
- ->onClick(route('users.show', $target->id))
+ ->onClick(route('api.assets.show', $target->id))
)
)
);
diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php
index d0717ea4ff..7c82eec29d 100644
--- a/resources/lang/en-US/mail.php
+++ b/resources/lang/en-US/mail.php
@@ -14,6 +14,7 @@ return [
'Confirm_license_delivery' => 'License delivery confirmation',
'Consumable_checkout_notification' => 'Consumable checked out',
'Component_checkout_notification' => 'Component checked out',
+ 'Component_checkin_notification' => 'Component checked in',
'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',