A free open source IT asset/license management system
Store alert_on_response_id on CheckoutAcceptance
Marcus Moorecb183d3645d6
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.phpindex e647bcd9e0..52a30f4772 100644--- a/app/Listeners/CheckoutableListener.php+++ b/app/Listeners/CheckoutableListener.php@@ -227,6 +227,7 @@ class CheckoutableListenerif ($checkedOutToType != "App\Models\User") {return null;}+if (!$event->checkoutable->requireAcceptance()) {return null;}@@ -234,6 +235,11 @@ class CheckoutableListener$acceptance = new CheckoutAcceptance;$acceptance->checkoutable()->associate($event->checkoutable);$acceptance->assignedTo()->associate($event->checkedOutTo);++ if (data_get($event, 'checkoutable.model.category.alert_on_response')) {+ $acceptance->alert_on_response_id = auth()->id();+ }+$acceptance->save();return $acceptance;diff --git a/app/Models/Category.php b/app/Models/Category.phpindex 0fd896b35d..08bef4d3eb 100755--- a/app/Models/Category.php+++ b/app/Models/Category.php@@ -70,6 +70,7 @@ class Category extends SnipeModel'eula_text','name','require_acceptance',+ 'alert_on_response','use_default_eula','created_by','notes',diff --git a/tests/Feature/Checkouts/General/SettingAlertOnResponseTest.php b/tests/Feature/Checkouts/General/SettingAlertOnResponseTest.phpnew file mode 100644index 0000000000..ac3a445c6f--- /dev/null+++ b/tests/Feature/Checkouts/General/SettingAlertOnResponseTest.php@@ -0,0 +1,37 @@+<?php++namespace Tests\Feature\Checkouts\General;++use App\Models\Asset;+use App\Models\Statuslabel;+use App\Models\User;+use Tests\TestCase;++class SettingAlertOnResponseTest extends TestCase+{+ public function testSetsAlertOnResponseCorrectly()+ {+ $asset = Asset::factory()->create();+ $asset->model->category->update([+ 'require_acceptance' => true,+ 'alert_on_response' => true,+ ]);++ $actor = User::factory()->checkoutAssets()->create();+ $assignedUser = User::factory()->create();++ $this->actingAs($actor)+ ->post(route('hardware.checkout.store', $asset), [+ 'checkout_to_type' => 'user',+ 'status_id' => (string) Statuslabel::factory()->readyToDeploy()->create()->id,+ 'assigned_user' => $assignedUser->id,+ ]);++ $this->assertDatabaseHas('checkout_acceptances', [+ 'checkoutable_type' => Asset::class,+ 'checkoutable_id' => $asset->id,+ 'assigned_to_id' => $assignedUser->id,+ 'alert_on_response_id' => $actor->id,+ ]);+ }+}