Skip to content

A free open source IT asset/license management system

Updates checkout notifications to use new routes for accepting

Till Deeke72b43b652665
diff --git a/app/Listeners/SendingCheckOutNotificationsListener.php b/app/Listeners/SendingCheckOutNotificationsListener.php
index 195962c498..1968c13d1a 100644
--- a/app/Listeners/SendingCheckOutNotificationsListener.php
+++ b/app/Listeners/SendingCheckOutNotificationsListener.php
@@ -9,69 +9,100 @@ use App\Notifications\CheckoutAccessoryNotification;
use App\Notifications\CheckoutAssetNotification;
use App\Notifications\CheckoutConsumableNotification;
use App\Notifications\CheckoutLicenseNotification;
+use Illuminate\Support\Facades\Notification;
class SendingCheckOutNotificationsListener
{
/**
- * Handle user login events.
+ * Notify the user about the checked out consumable
*/
public function onConsumableCheckedOut($event) {
/**
- * Notify the user about the checked out consumable
+ * When the item wasn't checked out to a user, we can't send notifications
*/
- $this->sendNotification(CheckoutConsumableNotification::class, $event->logEntry);
- }
+ if(! $event->checkedOutTo instanceof User) {
+ return;
+ }
+ Notification::send(
+ $this->getNotifiables($event),
+ new CheckoutConsumableNotification($event->consumable, $event->checkedOutTo, $event->checkedOutBy, $event->note)
+ );
+ }
+
+ /**
+ * Notify the user about the checked out accessory
+ */
public function onAccessoryCheckedOut($event) {
/**
- * Notify the user about the checked out accessory
+ * When the item wasn't checked out to a user, we can't send notifications
*/
- $this->sendNotification(CheckoutAccessoryNotification::class, $event->logEntry);
+ if(! $event->checkedOutTo instanceof User) {
+ return;
+ }
+
+ Notification::send(
+ $this->getNotifiables($event),
+ new CheckoutAccessoryNotification($event->accessory, $event->checkedOutTo, $event->checkedOutBy, $event->note)
+ );
}
+ /**
+ * Notify the user about the checked out license
+ */
public function onLicenseCheckedOut($event) {
/**
- * Notify the user about the checked out license
+ * When the item wasn't checked out to a user, we can't send notifications
*/
- $this->sendNotification(CheckoutLicenseNotification::class, $event->logEntry);
- }
+ if(! $event->checkedOutTo instanceof User) {
+ return;
+ }
- public function onAssetCheckedOut($event) {
- /**
- * Notify the user about the checked out asset
- */
- $this->sendNotification(CheckoutAssetNotification::class, $event->logEntry);
+ Notification::send(
+ $this->getNotifiables($event),
+ new CheckoutLicenseNotification($event->license, $event->checkedOutTo, $event->checkedOutBy, $event->note)
+ );
}
-
- private function sendNotification($notificationClass, $logEntry) {
+
+ /**
+ * Notify the user about the checked out asset
+ */
+ public function onAssetCheckedOut($event) {
/**
- * When the item isn't checked out to a user, we can't send notifications
+ * When the item wasn't checked out to a user, we can't send notifications
*/
- if(! $logEntry->target instanceof User) {
+ if(! $event->checkedOutTo instanceof User) {
return;
}
- $params = [
- 'log_id' => $logEntry->id,
- 'item' => $logEntry->item,
- 'target_type' => $logEntry->target_type,
- 'admin' => $logEntry->user,
+ Notification::send(
+ $this->getNotifiables($event),
+ new CheckoutAssetNotification($event->asset, $event->checkedOutTo, $event->checkedOutBy, $event->note)
+ );
+ }
- 'target' => $logEntry->target,
- 'note' => $logEntry->note,
- 'settings' => Setting::getSettings(),
- ];
+ /**
+ * Gets the entities to be notified of the passed event
+ *
+ * @param Event $event
+ * @return Collection
+ */
+ private function getNotifiables($event) {
+ $notifiables = collect();
- $logEntry->target->notify(new $notificationClass($params));
+ /**
+ * Notify the user who checked out the item
+ */
+ $notifiables->push($event->checkedOutTo);
/**
* Notify Admin users if the settings is activated
*/
if (Setting::getSettings()->admin_cc_email != '') {
- $recipient = new AdminRecipient();
+ $notifiables->push(new AdminRecipient());
+ }
- $recipient->notify(new $notificationClass($params));
- }
+ return $notifiables;
}
/**
diff --git a/app/Notifications/CheckoutAccessoryNotification.php b/app/Notifications/CheckoutAccessoryNotification.php
index 4e8950619d..3b29a21984 100644
--- a/app/Notifications/CheckoutAccessoryNotification.php
+++ b/app/Notifications/CheckoutAccessoryNotification.php
@@ -2,6 +2,7 @@
namespace App\Notifications;
+use App\Models\Accessory;
use App\Models\Setting;
use App\Models\SnipeModel;
use App\Models\User;
@@ -15,33 +16,20 @@ use Illuminate\Support\Facades\Mail;
class CheckoutAccessoryNotification extends Notification
{
use Queueable;
- /**
- * @var
- */
- private $params;
/**
* Create a new notification instance.
- *
- * @param $params
*/
- public function __construct($params)
+ public function __construct(Accessory $accessory, $checkedOutTo, User $checkedOutBy, $acceptance, $note)
{
- $this->target = $params['target'];
- $this->item = $params['item'];
- $this->admin = $params['admin'];
- $this->log_id = $params['log_id'];
- $this->note = '';
- $this->last_checkout = '';
- $this->expected_checkin = '';
- $this->target_type = $params['target_type'];
- $this->settings = $params['settings'];
-
- if (array_key_exists('note', $params)) {
- $this->note = $params['note'];
- }
+ $this->item = $accessory;
+ $this->admin = $checkedOutBy;
+ $this->note = $note;
+ $this->target = $checkedOutTo;
+ $this->acceptance = $acceptance;
+ $this->settings = Setting::getSettings();
}
@@ -140,7 +128,7 @@ class CheckoutAccessoryNotification extends Notification
'target' => $this->target,
'eula' => $eula,
'req_accept' => $req_accept,
- 'accept_url' => url('/').'/account/accept-asset/'.$this->log_id,
+ 'accept_url' => route('account.accept.item', ['accessory', $this->item->id]),
])
->subject(trans('mail.Confirm_accessory_delivery'));
diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php
index 8451d6dcd9..f0323342f0 100644
--- a/app/Notifications/CheckoutAssetNotification.php
+++ b/app/Notifications/CheckoutAssetNotification.php
@@ -2,6 +2,7 @@
namespace App\Notifications;
+use App\Models\Asset;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Bus\Queueable;
@@ -13,31 +14,24 @@ use Illuminate\Contracts\Queue\ShouldQueue;
class CheckoutAssetNotification extends Notification
{
use Queueable;
- /**
- * @var
- */
- private $params;
/**
* Create a new notification instance.
*
* @param $params
*/
- public function __construct($params)
+ public function __construct(Asset $asset, $checkedOutTo, User $checkedOutBy, $note)
{
- $this->target = $params['target'];
- $this->item = $params['item'];
- $this->admin = $params['admin'];
- $this->log_id = $params['log_id'];
- $this->note = '';
+
+ $this->item = $asset;
+ $this->admin = $checkedOutBy;
+ $this->note = $note;
+ $this->target = $checkedOutTo;
+
+ $this->settings = Setting::getSettings();
+
$this->last_checkout = '';
$this->expected_checkin = '';
- $this->target_type = $params['target_type'];
- $this->settings = $params['settings'];
-
- if (array_key_exists('note', $params)) {
- $this->note = $params['note'];
- }
if ($this->item->last_checkout) {
$this->last_checkout = \App\Helpers\Helper::getFormattedDateObject($this->item->last_checkout, 'date',
@@ -151,12 +145,11 @@ class CheckoutAssetNotification extends Notification
'item' => $this->item,
'admin' => $this->admin,
'note' => $this->note,
- 'log_id' => $this->note,
'target' => $this->target,
'fields' => $fields,
'eula' => $eula,
'req_accept' => $req_accept,
- 'accept_url' => url('/').'/account/accept-asset/'.$this->log_id,
+ 'accept_url' => route('account.accept.item', ['asset', $this->item->id]),
'last_checkout' => $this->last_checkout,
'expected_checkin' => $this->expected_checkin,
])
diff --git a/app/Notifications/CheckoutConsumableNotification.php b/app/Notifications/CheckoutConsumableNotification.php
index d9a80bfc3c..7c6dfb7b3f 100644
--- a/app/Notifications/CheckoutConsumableNotification.php
+++ b/app/Notifications/CheckoutConsumableNotification.php
@@ -2,6 +2,7 @@
namespace App\Notifications;
+use App\Models\Consumable;
use App\Models\Setting;
use App\Models\SnipeModel;
use App\Models\User;
@@ -25,21 +26,15 @@ class CheckoutConsumableNotification extends Notification
*
* @param $params
*/
- public function __construct($params)
+ public function __construct(Consumable $consumable, $checkedOutTo, User $checkedOutBy, $note)
{
- $this->target = $params['target'];
- $this->item = $params['item'];
- $this->admin = $params['admin'];
- $this->log_id = $params['log_id'];
- $this->note = '';
- $this->last_checkout = '';
- $this->expected_checkin = '';
- $this->target_type = $params['target_type'];
- $this->settings = $params['settings'];
-
- if (array_key_exists('note', $params)) {
- $this->note = $params['note'];
- }
+
+ $this->item = $consumable;
+ $this->admin = $checkedOutBy;
+ $this->note = $note;
+ $this->target = $checkedOutTo;
+
+ $this->settings = Setting::getSettings();
}
@@ -131,11 +126,10 @@ class CheckoutConsumableNotification extends Notification
'item' => $this->item,
'admin' => $this->admin,
'note' => $this->note,
- 'log_id' => $this->note,
'target' => $this->target,
'eula' => $eula,
'req_accept' => $req_accept,
- 'accept_url' => url('/').'/account/accept-asset/'.$this->log_id,
+ 'accept_url' => route('account.accept.item', ['consumable', $this->item->id]),
])
->subject(trans('mail.Confirm_consumable_delivery'));
diff --git a/app/Notifications/CheckoutLicenseNotification.php b/app/Notifications/CheckoutLicenseNotification.php
index 93530e2cde..e5c697b2a0 100644
--- a/app/Notifications/CheckoutLicenseNotification.php
+++ b/app/Notifications/CheckoutLicenseNotification.php
@@ -2,6 +2,7 @@
namespace App\Notifications;
+use App\Models\License;
use App\Models\Setting;
use App\Models\SnipeModel;
use App\Models\User;
@@ -25,23 +26,14 @@ class CheckoutLicenseNotification extends Notification
*
* @param $params
*/
- public function __construct($params)
+ public function __construct(License $license, $checkedOutTo, User $checkedOutBy, $note)
{
- $this->target = $params['target'];
- $this->item = $params['item'];
- $this->admin = $params['admin'];
- $this->log_id = $params['log_id'];
- $this->note = '';
- $this->target_type = $params['target_type'];
- $this->settings = $params['settings'];
- $this->target_type = $params['target_type'];
-
- if (array_key_exists('note', $params)) {
- $this->note = $params['note'];
- }
-
-
+ $this->item = $license;
+ $this->admin = $checkedOutBy;
+ $this->note = $note;
+ $this->target = $checkedOutTo;
+ $this->settings = Setting::getSettings();
}
/**
@@ -133,7 +125,7 @@ class CheckoutLicenseNotification extends Notification
'target' => $this->target,
'eula' => $eula,
'req_accept' => $req_accept,
- 'accept_url' => url('/').'/account/accept-asset/'.$this->log_id,
+ 'accept_url' => route('account.accept.item', ['license', $this->item->id]),
])
->subject(trans('mail.Confirm_license_delivery'));