A free open source IT asset/license management system
Send to alert email
Marcus Moore67edb7d39699
diff --git a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php b/app/Listeners/CheckoutablesCheckedOutInBulkListener.phpindex 65259c06de..bd0b395b7a 100644--- a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php+++ b/app/Listeners/CheckoutablesCheckedOutInBulkListener.php@@ -4,6 +4,8 @@ namespace App\Listeners;use App\Events\CheckoutablesCheckedOutInBulk;use App\Mail\BulkAssetCheckoutMail;+use App\Models\Setting;+use Illuminate\Support\Collection;use Illuminate\Support\Facades\Mail;class CheckoutablesCheckedOutInBulkListener@@ -19,7 +21,10 @@ class CheckoutablesCheckedOutInBulkListenerpublic function handle(CheckoutablesCheckedOutInBulk $event): void{- if ($event->target->email) {+ $shouldSendEmailToUser = $this->shouldSendCheckoutEmailToUser($event->assets);+ $shouldSendEmailToAlertAddress = $this->shouldSendEmailToAlertAddress();++ if ($shouldSendEmailToUser && $event->target->email) {Mail::to($event->target)->send(new BulkAssetCheckoutMail($event->assets,$event->target,@@ -30,6 +35,44 @@ class CheckoutablesCheckedOutInBulkListener));}- // @todo: check CheckoutableListener::onCheckedOut() for implementation+ if ($shouldSendEmailToAlertAddress && Setting::getSettings()->admin_cc_email) {+ Mail::to(Setting::getSettings()->admin_cc_email)->send(new BulkAssetCheckoutMail(+ $event->assets,+ $event->target,+ $event->admin,+ $event->checkout_at,+ $event->expected_checkin,+ $event->note,+ ));+ }+ }++ private function shouldSendCheckoutEmailToUser(Collection $assets): bool+ {+ // @todo: how to handle assets having eula?++ return $this->requiresAcceptance($assets);+ }++ private function shouldSendEmailToAlertAddress(): bool+ {+ $setting = Setting::getSettings();++ if (!$setting) {+ return false;+ }++ if ($setting->admin_cc_always) {+ return true;+ }++ return (bool) $setting->admin_cc_email;+ }++ private function requiresAcceptance(Collection $assets): bool+ {+ return (bool) $assets->reduce(+ fn($count, $asset) => $count + $asset->requireAcceptance()+ );}}diff --git a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.phpindex 92a3cf648e..080f6a5d10 100644--- a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php+++ b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php@@ -86,6 +86,22 @@ class BulkCheckoutEmailTest extends TestCase});}+ public function test_email_is_sent_to_cc_address_when_admin_cc_always_enabled()+ {+ $this->settings->enableAdminCC('[email protected]');+ $this->settings->enableAdminCCAlways();++ $this->assets = Asset::factory()->count(2)->create();++ $this->dispatchEvent();++ Mail::assertNotSent(CheckoutAssetMail::class);++ Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) {+ return $mail->hasTo('[email protected]');+ });+ }+public function test_webbook_is_sent(){$this->markTestIncomplete();