From 02ff646da4388422d260ed50d8e93ea7bc57dab0 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 16 Oct 2024 15:44:45 -0700 Subject: [PATCH] adds checkin license mailable --- app/Listeners/CheckoutableListener.php | 3 +- app/Mail/CheckinLicenseMail.php | 79 +++++++++++++++++++ .../CheckinAccessoryNotification.php | 33 -------- .../CheckinLicenseSeatNotification.php | 27 ------- .../markdown/checkin-license.blade.php | 0 5 files changed, 81 insertions(+), 61 deletions(-) create mode 100644 app/Mail/CheckinLicenseMail.php rename resources/views/{notifications => mail}/markdown/checkin-license.blade.php (100%) 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 @@ +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 + */ + 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