mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 05:47:28 -08:00
adds checkin license mailable
This commit is contained in:
parent
4becdca8aa
commit
02ff646da4
|
@ -4,6 +4,7 @@ namespace App\Listeners;
|
|||
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
use App\Mail\CheckinAccessoryMail;
|
||||
use App\Mail\CheckinLicenseMail;
|
||||
use App\Mail\CheckoutAccessoryMail;
|
||||
use App\Mail\CheckoutAssetMail;
|
||||
use App\Mail\CheckinAssetMail;
|
||||
|
@ -242,8 +243,8 @@ class CheckoutableListener
|
|||
$lookup = [
|
||||
Accessory::class => CheckinAccessoryMail::class,
|
||||
Asset::class => CheckinAssetMail::class,
|
||||
LicenseSeat::class => CheckinLicenseMail::class,
|
||||
// Consumable::class =>
|
||||
// LicenseSeat::class =>
|
||||
];
|
||||
$mailable= $lookup[get_class($event->checkoutable)];
|
||||
|
||||
|
|
79
app/Mail/CheckinLicenseMail.php
Normal file
79
app/Mail/CheckinLicenseMail.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\LicenseSeat;
|
||||
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;
|
||||
|
||||
class CheckinLicenseMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(LicenseSeat $licenseSeat, $checkedOutTo, User $checkedInBy, $note)
|
||||
{
|
||||
$this->target = $checkedOutTo;
|
||||
$this->item = $licenseSeat->license;
|
||||
$this->admin = $checkedInBy;
|
||||
$this->note = $note;
|
||||
$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.License_Checkin_Notification'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'mail.markdown.checkin-license',
|
||||
with: [
|
||||
'item' => $this->item,
|
||||
'admin' => $this->admin,
|
||||
'note' => $this->note,
|
||||
'target' => $this->target,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -58,19 +58,6 @@ class CheckinAccessoryNotification extends Notification
|
|||
$notifyBy[] = 'slack';
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Only send notifications to users that have email addresses
|
||||
// */
|
||||
// if ($this->target instanceof User && $this->target->email != '') {
|
||||
// Log::debug('The target is a user');
|
||||
//
|
||||
// if ($this->item->checkin_email()) {
|
||||
// $notifyBy[] = 'mail';
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Log::debug('checkin_email on this category is '.$this->item->checkin_email());
|
||||
|
||||
return $notifyBy;
|
||||
}
|
||||
|
||||
|
@ -142,24 +129,4 @@ class CheckinAccessoryNotification extends Notification
|
|||
);
|
||||
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Get the mail representation of the notification.
|
||||
// *
|
||||
// * @param mixed $notifiable
|
||||
// * @return \Illuminate\Notifications\Messages\MailMessage
|
||||
// */
|
||||
// public function toMail()
|
||||
// {
|
||||
// Log::debug('to email called');
|
||||
//
|
||||
// return (new MailMessage)->markdown('notifications.markdown.checkin-accessory',
|
||||
// [
|
||||
// 'item' => $this->item,
|
||||
// 'admin' => $this->admin,
|
||||
// 'note' => $this->note,
|
||||
// 'target' => $this->target,
|
||||
// ])
|
||||
// ->subject(trans('mail.Accessory_Checkin_Notification'));
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -61,14 +61,6 @@ class CheckinLicenseSeatNotification extends Notification
|
|||
$notifyBy[] = 'slack';
|
||||
}
|
||||
|
||||
/**
|
||||
* Only send checkin notifications to users if the category
|
||||
* has the corresponding checkbox checked.
|
||||
*/
|
||||
if ($this->item->checkin_email() && $this->target instanceof User && $this->target->email != '') {
|
||||
$notifyBy[] = 'mail';
|
||||
}
|
||||
|
||||
return $notifyBy;
|
||||
}
|
||||
|
||||
|
@ -149,23 +141,4 @@ class CheckinLicenseSeatNotification extends Notification
|
|||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail()
|
||||
{
|
||||
return (new MailMessage)->markdown('notifications.markdown.checkin-license',
|
||||
[
|
||||
'item' => $this->item,
|
||||
'admin' => $this->admin,
|
||||
'note' => $this->note,
|
||||
'target' => $this->target,
|
||||
])
|
||||
->subject(trans('mail.License_Checkin_Notification'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue