mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-23 12:44:12 -08:00
adds Checkout Consumable mailable and slackwebhook channel to notifs
This commit is contained in:
parent
02ff646da4
commit
02bda3cd95
|
@ -8,6 +8,7 @@ use App\Mail\CheckinLicenseMail;
|
|||
use App\Mail\CheckoutAccessoryMail;
|
||||
use App\Mail\CheckoutAssetMail;
|
||||
use App\Mail\CheckinAssetMail;
|
||||
use App\Mail\CheckoutConsumableMail;
|
||||
use App\Mail\CheckoutLicenseMail;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Asset;
|
||||
|
@ -210,21 +211,22 @@ class CheckoutableListener
|
|||
{
|
||||
$notificationClass = null;
|
||||
|
||||
switch (true) {
|
||||
case $event->checkoutable instanceof Accessory:
|
||||
switch (get_class($event->checkoutable)) {
|
||||
case Accessory::class:
|
||||
$notificationClass = CheckoutAccessoryNotification::class;
|
||||
break;
|
||||
case $event->checkoutable instanceof Asset:
|
||||
case Asset::class:
|
||||
$notificationClass = CheckoutAssetNotification::class;
|
||||
break;
|
||||
case $event->checkoutable instanceof Consumable:
|
||||
case Consumable::class:
|
||||
$notificationClass = CheckoutConsumableNotification::class;
|
||||
break;
|
||||
case $event->checkoutable instanceof LicenseSeat:
|
||||
case LicenseSeat::class:
|
||||
$notificationClass = CheckoutLicenseSeatNotification::class;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return new $notificationClass($event->checkoutable, $event->checkedOutTo, $event->checkedOutBy, $acceptance, $event->note);
|
||||
}
|
||||
private function getCheckoutMailType($event, $acceptance){
|
||||
|
@ -232,7 +234,7 @@ class CheckoutableListener
|
|||
Accessory::class => CheckoutAccessoryMail::class,
|
||||
Asset::class => CheckoutAssetMail::class,
|
||||
LicenseSeat::class => CheckoutLicenseMail::class,
|
||||
// Consumable::class =>
|
||||
Consumable::class => CheckoutConsumableMail::class,
|
||||
];
|
||||
$mailable= $lookup[get_class($event->checkoutable)];
|
||||
|
||||
|
@ -244,8 +246,8 @@ class CheckoutableListener
|
|||
Accessory::class => CheckinAccessoryMail::class,
|
||||
Asset::class => CheckinAssetMail::class,
|
||||
LicenseSeat::class => CheckinLicenseMail::class,
|
||||
// Consumable::class =>
|
||||
];
|
||||
|
||||
$mailable= $lookup[get_class($event->checkoutable)];
|
||||
|
||||
return new $mailable($event->checkoutable, $event->checkedOutTo, $event->checkedInBy, $event->note);
|
||||
|
|
91
app/Mail/CheckoutConsumableMail.php
Normal file
91
app/Mail/CheckoutConsumableMail.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Consumable;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CheckoutConsumableMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(Consumable $consumable, $checkedOutTo, User $checkedOutBy, $acceptance, $note)
|
||||
{
|
||||
$this->item = $consumable;
|
||||
$this->admin = $checkedOutBy;
|
||||
$this->note = $note;
|
||||
$this->target = $checkedOutTo;
|
||||
$this->acceptance = $acceptance;
|
||||
|
||||
$this->settings = Setting::getSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
$from = null;
|
||||
$cc = [];
|
||||
|
||||
if (!empty(Setting::getSettings()->alert_email)) {
|
||||
$from = new Address(Setting::getSettings()->alert_email);
|
||||
}
|
||||
if (!empty(Setting::getSettings()->admin_cc_email)) {
|
||||
$cc[] = new Address(Setting::getSettings()->admin_cc_email);
|
||||
}
|
||||
|
||||
return new Envelope(
|
||||
from: $from ?? new Address('default@example.com', 'Default Sender'),
|
||||
cc: $cc,
|
||||
subject: trans('mail.Confirm_consumable_delivery'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
Log::debug($this->item->getImageUrl());
|
||||
$eula = $this->item->getEula();
|
||||
$req_accept = $this->item->requireAcceptance();
|
||||
|
||||
$accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance);
|
||||
|
||||
return new Content(
|
||||
markdown: 'mail.markdown.checkout-consumable',
|
||||
with: [
|
||||
'item' => $this->item,
|
||||
'admin' => $this->admin,
|
||||
'note' => $this->note,
|
||||
'target' => $this->target,
|
||||
'eula' => $eula,
|
||||
'req_accept' => $req_accept,
|
||||
'accept_url' => $accept_url,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ use App\Models\Accessory;
|
|||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Channels\SlackWebhookChannel;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
@ -55,7 +56,7 @@ class CheckinAccessoryNotification extends Notification
|
|||
}
|
||||
|
||||
if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general' ) {
|
||||
$notifyBy[] = 'slack';
|
||||
$notifyBy[] = SlackWebhookChannel::class;
|
||||
}
|
||||
|
||||
return $notifyBy;
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\Models\Consumable;
|
|||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Channels\SlackWebhookChannel;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
@ -61,36 +62,36 @@ class CheckoutConsumableNotification extends Notification
|
|||
}
|
||||
|
||||
if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general' ) {
|
||||
$notifyBy[] = 'slack';
|
||||
$notifyBy[] = SlackWebhookChannel::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only send notifications to users that have email addresses
|
||||
*/
|
||||
if ($this->target instanceof User && $this->target->email != '') {
|
||||
|
||||
/**
|
||||
* Send an email if the asset requires acceptance,
|
||||
* so the user can accept or decline the asset
|
||||
*/
|
||||
if ($this->item->requireAcceptance()) {
|
||||
$notifyBy[1] = 'mail';
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an email if the item has a EULA, since the user should always receive it
|
||||
*/
|
||||
if ($this->item->getEula()) {
|
||||
$notifyBy[1] = 'mail';
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an email if an email should be sent at checkin/checkout
|
||||
*/
|
||||
if ((method_exists($this->item, 'checkin_email')) && ($this->item->checkin_email())) {
|
||||
$notifyBy[1] = 'mail';
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * Only send notifications to users that have email addresses
|
||||
// */
|
||||
// if ($this->target instanceof User && $this->target->email != '') {
|
||||
//
|
||||
// /**
|
||||
// * Send an email if the asset requires acceptance,
|
||||
// * so the user can accept or decline the asset
|
||||
// */
|
||||
// if ($this->item->requireAcceptance()) {
|
||||
// $notifyBy[1] = 'mail';
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Send an email if the item has a EULA, since the user should always receive it
|
||||
// */
|
||||
// if ($this->item->getEula()) {
|
||||
// $notifyBy[1] = 'mail';
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Send an email if an email should be sent at checkin/checkout
|
||||
// */
|
||||
// if ((method_exists($this->item, 'checkin_email')) && ($this->item->checkin_email())) {
|
||||
// $notifyBy[1] = 'mail';
|
||||
// }
|
||||
// }
|
||||
|
||||
return $notifyBy;
|
||||
}
|
||||
|
@ -165,30 +166,4 @@ class CheckoutConsumableNotification extends Notification
|
|||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail()
|
||||
{
|
||||
Log::debug($this->item->getImageUrl());
|
||||
$eula = $this->item->getEula();
|
||||
$req_accept = $this->item->requireAcceptance();
|
||||
|
||||
$accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance);
|
||||
|
||||
return (new MailMessage)->markdown('notifications.markdown.checkout-consumable',
|
||||
[
|
||||
'item' => $this->item,
|
||||
'admin' => $this->admin,
|
||||
'note' => $this->note,
|
||||
'target' => $this->target,
|
||||
'eula' => $eula,
|
||||
'req_accept' => $req_accept,
|
||||
'accept_url' => $accept_url,
|
||||
])
|
||||
->subject(trans('mail.Confirm_consumable_delivery'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\Models\LicenseSeat;
|
|||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Channels\SlackWebhookChannel;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
@ -60,7 +61,7 @@ class CheckoutLicenseSeatNotification extends Notification
|
|||
}
|
||||
|
||||
if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general' ) {
|
||||
$notifyBy[] = 'slack';
|
||||
$notifyBy[] = SlackWebhookChannel::class;
|
||||
}
|
||||
|
||||
return $notifyBy;
|
||||
|
|
Loading…
Reference in a new issue