A free open source IT asset/license management system
Add subject
Marcus Moore7424a5987bc6
diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.phpindex 583b710887..adb423581b 100644--- a/app/Http/Controllers/Account/AcceptanceController.php+++ b/app/Http/Controllers/Account/AcceptanceController.php@@ -342,10 +342,13 @@ class AcceptanceController extends Controllerif ($acceptance->alert_on_response_id) {try {- Mail::to(User::findOrFail($acceptance->alert_on_response_id))+ $recipient = User::findOrFail($acceptance->alert_on_response_id);++ Mail::to($recipient)->send(new CheckoutAcceptanceResponseMail(- (bool) $request->input('asset_acceptance') === 'accepted'- ));+ $recipient,+ $request->input('asset_acceptance') === 'accepted')+ );} catch (Exception $e) {Log::warning($e);}diff --git a/app/Mail/CheckoutAcceptanceResponseMail.php b/app/Mail/CheckoutAcceptanceResponseMail.phpindex 3eed73ed0a..bf4aad5e8e 100644--- a/app/Mail/CheckoutAcceptanceResponseMail.php+++ b/app/Mail/CheckoutAcceptanceResponseMail.php@@ -2,6 +2,7 @@namespace App\Mail;+use App\Models\User;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Mail\Mailable;@@ -13,14 +14,16 @@ class CheckoutAcceptanceResponseMail extends Mailable{use Queueable, SerializesModels;- public bool $accepted;+ public bool $wasAccepted;+ public User $recipient;/*** Create a new message instance.*/- public function __construct(bool $accepted)+ public function __construct(User $recipient, bool $wasAccepted){- $this->accepted = $accepted;+ $this->recipient = $recipient;+ $this->wasAccepted = $wasAccepted;}/**@@ -29,7 +32,7 @@ class CheckoutAcceptanceResponseMail extends Mailablepublic function envelope(): Envelope{return new Envelope(- subject: 'Checkout Acceptance Response Mail',+ subject: 'A checkout you initiated was ' . ($this->wasAccepted ? 'accepted' : 'rejected'),);}@@ -40,6 +43,10 @@ class CheckoutAcceptanceResponseMail extends Mailable{return new Content(markdown: 'mail.markdown.checkout-acceptance-response',+ with: [+ 'recipient' => $this->recipient,+ 'wasAccepted' => $this->wasAccepted,+ ]);}diff --git a/resources/views/mail/markdown/checkout-acceptance-response.blade.php b/resources/views/mail/markdown/checkout-acceptance-response.blade.phpindex 5fe2b643e2..472e39b308 100644--- a/resources/views/mail/markdown/checkout-acceptance-response.blade.php+++ b/resources/views/mail/markdown/checkout-acceptance-response.blade.php@@ -1,5 +1,5 @@@component('mail::message')-# {{ trans('mail.hello') }} {{ $target->present()->fullName() }},+# {{ trans('mail.hello') }} {{ $recipient->present()->fullName() }},{{ trans('mail.best_regards') }}diff --git a/tests/Feature/Notifications/Email/CheckoutResponseEmailTest.php b/tests/Feature/Notifications/Email/CheckoutResponseEmailTest.phpindex a761b77ce1..9174e5656d 100644--- a/tests/Feature/Notifications/Email/CheckoutResponseEmailTest.php+++ b/tests/Feature/Notifications/Email/CheckoutResponseEmailTest.php@@ -28,7 +28,7 @@ class CheckoutResponseEmailTest extends TestCase$this->acceptCheckout($checkoutAcceptance);- $this->assertEmailSentTo($initiator);+ $this->assertEmailSentTo($initiator, 'accepted');}public function test_declining_checkout_acceptance_configured_to_send_alert()@@ -42,7 +42,7 @@ class CheckoutResponseEmailTest extends TestCase$this->declineCheckout($checkoutAcceptance);- $this->assertEmailSentTo($initiator);+ $this->assertEmailSentTo($initiator, 'rejected');}public function test_accepting_checkout_acceptance_not_configured_to_send_alert()@@ -73,11 +73,10 @@ class CheckoutResponseEmailTest extends TestCase$this->assertEmailNotSentTo($initiator);}- private function assertEmailSentTo(User $user): void+ private function assertEmailSentTo(User $user, string $type): void{- Mail::assertSent(CheckoutAcceptanceResponseMail::class, function ($mail) use ($user) {- // @todo: better assertions? accepted vs declined?- return $mail->hasTo($user->email);+ Mail::assertSent(CheckoutAcceptanceResponseMail::class, function (CheckoutAcceptanceResponseMail $mail) use ($type, $user) {+ return $mail->hasTo($user->email) && $mail->assertHasSubject('A checkout you initiated was ' . $type);});}@@ -101,7 +100,7 @@ class CheckoutResponseEmailTest extends TestCase{$this->actingAs($checkoutAcceptance->assignedTo)->post(route('account.store-acceptance', $checkoutAcceptance), [- 'asset_acceptance' => 'declined',+ 'asset_acceptance' => 'rejected','note' => null,]);}