From 2584d603445bb0a82e722cd8b7a3dbf7f1c1d020 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 16 Oct 2024 15:38:49 -0700 Subject: [PATCH] adds Licenses seat checkout Mailable --- app/Listeners/CheckoutableListener.php | 3 +- app/Mail/CheckoutLicenseMail.php | 89 +++++++++++++++++++ .../CheckoutLicenseSeatNotification.php | 28 ------ .../markdown/checkout-license.blade.php | 0 routes/web.php | 6 +- 5 files changed, 95 insertions(+), 31 deletions(-) create mode 100644 app/Mail/CheckoutLicenseMail.php rename resources/views/{notifications => mail}/markdown/checkout-license.blade.php (100%) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 6acedd4d97..915ed5753a 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -7,6 +7,7 @@ use App\Mail\CheckinAccessoryMail; use App\Mail\CheckoutAccessoryMail; use App\Mail\CheckoutAssetMail; use App\Mail\CheckinAssetMail; +use App\Mail\CheckoutLicenseMail; use App\Models\Accessory; use App\Models\Asset; use App\Models\CheckoutAcceptance; @@ -229,8 +230,8 @@ class CheckoutableListener $lookup = [ Accessory::class => CheckoutAccessoryMail::class, Asset::class => CheckoutAssetMail::class, + LicenseSeat::class => CheckoutLicenseMail::class, // Consumable::class => -// LicenseSeat::class => ]; $mailable= $lookup[get_class($event->checkoutable)]; diff --git a/app/Mail/CheckoutLicenseMail.php b/app/Mail/CheckoutLicenseMail.php new file mode 100644 index 0000000000..8389f1136f --- /dev/null +++ b/app/Mail/CheckoutLicenseMail.php @@ -0,0 +1,89 @@ +item = $licenseSeat->license; + $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_license_delivery'), + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + $eula = method_exists($this->item, 'getEula') ? $this->item->getEula() : ''; + $req_accept = method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0; + + $accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance); + + return new Content( + markdown: 'mail.markdown.checkout-license', + 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 + */ + public function attachments(): array + { + return []; + } +} diff --git a/app/Notifications/CheckoutLicenseSeatNotification.php b/app/Notifications/CheckoutLicenseSeatNotification.php index 8e0273c66e..16f8c7c1d5 100644 --- a/app/Notifications/CheckoutLicenseSeatNotification.php +++ b/app/Notifications/CheckoutLicenseSeatNotification.php @@ -63,34 +63,6 @@ class CheckoutLicenseSeatNotification extends Notification $notifyBy[] = 'slack'; } - /** - * 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 ($this->item->checkin_email()) { - $notifyBy[1] = 'mail'; - } - } - return $notifyBy; } diff --git a/resources/views/notifications/markdown/checkout-license.blade.php b/resources/views/mail/markdown/checkout-license.blade.php similarity index 100% rename from resources/views/notifications/markdown/checkout-license.blade.php rename to resources/views/mail/markdown/checkout-license.blade.php diff --git a/routes/web.php b/routes/web.php index 756c6dd451..bcbe159b30 100644 --- a/routes/web.php +++ b/routes/web.php @@ -26,6 +26,7 @@ use App\Http\Controllers\Auth\ResetPasswordController; use App\Livewire\Importer; use App\Models\Accessory; use App\Models\Asset; +use App\Models\LicenseSeat; use App\Models\User; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Auth; @@ -57,7 +58,7 @@ Route::group(['middleware' => 'auth'], function () { * Locations */ Route::get('/test-email', function() { - $item = Accessory::find(1); // Load some test data + $item = LicenseSeat::find(1); // Load some test data $admin = User::find(1); $target = User::find(2); $acceptance = null; // Simulate acceptance data @@ -68,10 +69,11 @@ Route::group(['middleware' => 'auth'], function () { $fields = $item->model->fieldset->fields; } - return new \App\Mail\CheckinAccessoryMail( + return new \App\Mail\CheckoutLicenseMail( $item, $admin, $target, + $acceptance, $note); });