Skip to content

A free open source IT asset/license management system

adds checkin license mailable

Godfrey M02ff646da438
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php
index 915ed5753a..fe9f7b6d38 100644
--- a/app/Listeners/CheckoutableListener.php
+++ b/app/Listeners/CheckoutableListener.php
@@ -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)];
diff --git a/app/Mail/CheckinLicenseMail.php b/app/Mail/CheckinLicenseMail.php
new file mode 100644
index 0000000000..e567383f80
--- /dev/null
+++ b/app/Mail/CheckinLicenseMail.php
@@ -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('[email protected]', '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 [];
+ }
+}
diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php
index d36b77a850..777834aae7 100644
--- a/app/Notifications/CheckinAccessoryNotification.php
+++ b/app/Notifications/CheckinAccessoryNotification.php
@@ -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'));
-// }
}
diff --git a/app/Notifications/CheckinLicenseSeatNotification.php b/app/Notifications/CheckinLicenseSeatNotification.php
index 289e63a162..114011bd72 100644
--- a/app/Notifications/CheckinLicenseSeatNotification.php
+++ b/app/Notifications/CheckinLicenseSeatNotification.php
@@ -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'));
- }
}
diff --git a/resources/views/notifications/markdown/checkin-license.blade.php b/resources/views/mail/markdown/checkin-license.blade.php
similarity index 100%
rename from resources/views/notifications/markdown/checkin-license.blade.php
rename to resources/views/mail/markdown/checkin-license.blade.php