A free open source IT asset/license management system
Enable sending to manager
Marcus Moore333ebb88b9b0
diff --git a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php b/app/Listeners/CheckoutablesCheckedOutInBulkListener.phpindex fc3a5b4b65..2b141d86dd 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\Asset;+use App\Models\Location;use App\Models\Setting;use Exception;use Illuminate\Support\Collection;@@ -26,9 +28,11 @@ class CheckoutablesCheckedOutInBulkListener$shouldSendEmailToUser = $this->shouldSendCheckoutEmailToUser($event->assets);$shouldSendEmailToAlertAddress = $this->shouldSendEmailToAlertAddress($event->assets);- if ($shouldSendEmailToUser && $event->target->email) {+ $notifiableUser = $this->getNotifiableUser($event);++ if ($shouldSendEmailToUser && $notifiableUser) {try {- Mail::to($event->target)->send(new BulkAssetCheckoutMail(+ Mail::to($notifiableUser)->send(new BulkAssetCheckoutMail($event->assets,$event->target,$event->admin,@@ -94,4 +98,19 @@ class CheckoutablesCheckedOutInBulkListener);}+ private function getNotifiableUser(CheckoutablesCheckedOutInBulk $event)+ {+ $target = $event->target;++ if ($target instanceof Asset) {+ $target->load('assignedTo');+ return $target->assignedto;+ }++ if ($target instanceof Location) {+ return $target->manager;+ }++ return $target;+ }}diff --git a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.phpindex e208c9d541..8331564000 100644--- a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php+++ b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php@@ -9,6 +9,7 @@ use App\Models\Location;use App\Models\User;use Illuminate\Support\Facades\Mail;use PHPUnit\Framework\Attributes\Group;+use RuntimeException;use Tests\TestCase;#[Group('notifications')]@@ -155,23 +156,40 @@ class BulkCheckoutEmailTest extends TestCaseprivate function sendRequest(){- $types = [- User::class => 'user',- Location::class => 'location',- Asset::class => 'asset',- ];-$this->actingAs($this->admin)->followingRedirects()- ->post(route('hardware.bulkcheckout.store'), [+ ->post(route('hardware.bulkcheckout.store'), array_merge(['selected_assets' => $this->assets->pluck('id')->toArray(),- 'checkout_to_type' => $types[get_class($this->target)],- 'assigned_user' => $this->target->id,- 'assigned_asset' => null,'checkout_at' => now()->subWeek()->format('Y-m-d'),'expected_checkin' => now()->addWeek()->format('Y-m-d'),'note' => null,- ])+ ], $this->getAssignedArray()))->assertOk();}++ private function getAssignedArray(): array+ {+ if ($this->target instanceof User) {+ return [+ 'checkout_to_type' => 'user',+ 'assigned_user' => $this->target->id,+ ];+ }++ if ($this->target instanceof Location) {+ return [+ 'checkout_to_type' => 'location',+ 'assigned_location' => $this->target->id,+ ];+ }++ if ($this->target instanceof Asset) {+ return [+ 'checkout_to_type' => 'asset',+ 'assigned_asset' => $this->target->id,+ ];+ }++ throw new RuntimeException('invalid target type');+ }}