Updates checkout notifications to use new routes for accepting

This commit is contained in:
Till Deeke 2018-07-28 00:27:19 +02:00
parent e0423418d2
commit 72b43b6526
5 changed files with 112 additions and 114 deletions

View file

@ -9,69 +9,100 @@ use App\Notifications\CheckoutAccessoryNotification;
use App\Notifications\CheckoutAssetNotification; use App\Notifications\CheckoutAssetNotification;
use App\Notifications\CheckoutConsumableNotification; use App\Notifications\CheckoutConsumableNotification;
use App\Notifications\CheckoutLicenseNotification; use App\Notifications\CheckoutLicenseNotification;
use Illuminate\Support\Facades\Notification;
class SendingCheckOutNotificationsListener class SendingCheckOutNotificationsListener
{ {
/** /**
* Handle user login events. * Notify the user about the checked out consumable
*/ */
public function onConsumableCheckedOut($event) { 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) {
}
public function onAccessoryCheckedOut($event) {
/**
* Notify the user about the checked out accessory
*/
$this->sendNotification(CheckoutAccessoryNotification::class, $event->logEntry);
}
public function onLicenseCheckedOut($event) {
/**
* Notify the user about the checked out license
*/
$this->sendNotification(CheckoutLicenseNotification::class, $event->logEntry);
}
public function onAssetCheckedOut($event) {
/**
* Notify the user about the checked out asset
*/
$this->sendNotification(CheckoutAssetNotification::class, $event->logEntry);
}
private function sendNotification($notificationClass, $logEntry) {
/**
* When the item isn't checked out to a user, we can't send notifications
*/
if(! $logEntry->target instanceof User) {
return; return;
} }
$params = [ Notification::send(
'log_id' => $logEntry->id, $this->getNotifiables($event),
'item' => $logEntry->item, new CheckoutConsumableNotification($event->consumable, $event->checkedOutTo, $event->checkedOutBy, $event->note)
'target_type' => $logEntry->target_type, );
'admin' => $logEntry->user, }
/**
* Notify the user about the checked out accessory
*/
public function onAccessoryCheckedOut($event) {
/**
* When the item wasn't checked out to a user, we can't send notifications
*/
if(! $event->checkedOutTo instanceof User) {
return;
}
'target' => $logEntry->target, Notification::send(
'note' => $logEntry->note, $this->getNotifiables($event),
'settings' => Setting::getSettings(), new CheckoutAccessoryNotification($event->accessory, $event->checkedOutTo, $event->checkedOutBy, $event->note)
]; );
}
$logEntry->target->notify(new $notificationClass($params)); /**
* Notify the user about the checked out license
*/
public function onLicenseCheckedOut($event) {
/**
* When the item wasn't checked out to a user, we can't send notifications
*/
if(! $event->checkedOutTo instanceof User) {
return;
}
Notification::send(
$this->getNotifiables($event),
new CheckoutLicenseNotification($event->license, $event->checkedOutTo, $event->checkedOutBy, $event->note)
);
}
/**
* Notify the user about the checked out asset
*/
public function onAssetCheckedOut($event) {
/**
* When the item wasn't checked out to a user, we can't send notifications
*/
if(! $event->checkedOutTo instanceof User) {
return;
}
Notification::send(
$this->getNotifiables($event),
new CheckoutAssetNotification($event->asset, $event->checkedOutTo, $event->checkedOutBy, $event->note)
);
}
/**
* Gets the entities to be notified of the passed event
*
* @param Event $event
* @return Collection
*/
private function getNotifiables($event) {
$notifiables = collect();
/**
* Notify the user who checked out the item
*/
$notifiables->push($event->checkedOutTo);
/** /**
* Notify Admin users if the settings is activated * Notify Admin users if the settings is activated
*/ */
if (Setting::getSettings()->admin_cc_email != '') { if (Setting::getSettings()->admin_cc_email != '') {
$recipient = new AdminRecipient(); $notifiables->push(new AdminRecipient());
}
$recipient->notify(new $notificationClass($params)); return $notifiables;
}
} }
/** /**

View file

@ -2,6 +2,7 @@
namespace App\Notifications; namespace App\Notifications;
use App\Models\Accessory;
use App\Models\Setting; use App\Models\Setting;
use App\Models\SnipeModel; use App\Models\SnipeModel;
use App\Models\User; use App\Models\User;
@ -15,33 +16,20 @@ use Illuminate\Support\Facades\Mail;
class CheckoutAccessoryNotification extends Notification class CheckoutAccessoryNotification extends Notification
{ {
use Queueable; use Queueable;
/**
* @var
*/
private $params;
/** /**
* Create a new notification instance. * 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, 'target' => $this->target,
'eula' => $eula, 'eula' => $eula,
'req_accept' => $req_accept, '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')); ->subject(trans('mail.Confirm_accessory_delivery'));

View file

@ -2,6 +2,7 @@
namespace App\Notifications; namespace App\Notifications;
use App\Models\Asset;
use App\Models\Setting; use App\Models\Setting;
use App\Models\User; use App\Models\User;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
@ -13,31 +14,24 @@ use Illuminate\Contracts\Queue\ShouldQueue;
class CheckoutAssetNotification extends Notification class CheckoutAssetNotification extends Notification
{ {
use Queueable; use Queueable;
/**
* @var
*/
private $params;
/** /**
* Create a new notification instance. * Create a new notification instance.
* *
* @param $params * @param $params
*/ */
public function __construct($params) public function __construct(Asset $asset, $checkedOutTo, User $checkedOutBy, $note)
{ {
$this->target = $params['target'];
$this->item = $params['item']; $this->item = $asset;
$this->admin = $params['admin']; $this->admin = $checkedOutBy;
$this->log_id = $params['log_id']; $this->note = $note;
$this->note = ''; $this->target = $checkedOutTo;
$this->settings = Setting::getSettings();
$this->last_checkout = ''; $this->last_checkout = '';
$this->expected_checkin = ''; $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) { if ($this->item->last_checkout) {
$this->last_checkout = \App\Helpers\Helper::getFormattedDateObject($this->item->last_checkout, 'date', $this->last_checkout = \App\Helpers\Helper::getFormattedDateObject($this->item->last_checkout, 'date',
@ -151,12 +145,11 @@ class CheckoutAssetNotification extends Notification
'item' => $this->item, 'item' => $this->item,
'admin' => $this->admin, 'admin' => $this->admin,
'note' => $this->note, 'note' => $this->note,
'log_id' => $this->note,
'target' => $this->target, 'target' => $this->target,
'fields' => $fields, 'fields' => $fields,
'eula' => $eula, 'eula' => $eula,
'req_accept' => $req_accept, '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, 'last_checkout' => $this->last_checkout,
'expected_checkin' => $this->expected_checkin, 'expected_checkin' => $this->expected_checkin,
]) ])

View file

@ -2,6 +2,7 @@
namespace App\Notifications; namespace App\Notifications;
use App\Models\Consumable;
use App\Models\Setting; use App\Models\Setting;
use App\Models\SnipeModel; use App\Models\SnipeModel;
use App\Models\User; use App\Models\User;
@ -25,21 +26,15 @@ class CheckoutConsumableNotification extends Notification
* *
* @param $params * @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->item = $consumable;
$this->note = $params['note']; $this->admin = $checkedOutBy;
} $this->note = $note;
$this->target = $checkedOutTo;
$this->settings = Setting::getSettings();
} }
@ -131,11 +126,10 @@ class CheckoutConsumableNotification extends Notification
'item' => $this->item, 'item' => $this->item,
'admin' => $this->admin, 'admin' => $this->admin,
'note' => $this->note, 'note' => $this->note,
'log_id' => $this->note,
'target' => $this->target, 'target' => $this->target,
'eula' => $eula, 'eula' => $eula,
'req_accept' => $req_accept, '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')); ->subject(trans('mail.Confirm_consumable_delivery'));

View file

@ -2,6 +2,7 @@
namespace App\Notifications; namespace App\Notifications;
use App\Models\License;
use App\Models\Setting; use App\Models\Setting;
use App\Models\SnipeModel; use App\Models\SnipeModel;
use App\Models\User; use App\Models\User;
@ -25,23 +26,14 @@ class CheckoutLicenseNotification extends Notification
* *
* @param $params * @param $params
*/ */
public function __construct($params) public function __construct(License $license, $checkedOutTo, User $checkedOutBy, $note)
{ {
$this->target = $params['target']; $this->item = $license;
$this->item = $params['item']; $this->admin = $checkedOutBy;
$this->admin = $params['admin']; $this->note = $note;
$this->log_id = $params['log_id']; $this->target = $checkedOutTo;
$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->settings = Setting::getSettings();
} }
/** /**
@ -133,7 +125,7 @@ class CheckoutLicenseNotification extends Notification
'target' => $this->target, 'target' => $this->target,
'eula' => $eula, 'eula' => $eula,
'req_accept' => $req_accept, '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')); ->subject(trans('mail.Confirm_license_delivery'));