From a08e0bd547a1e1dad0d68d51d8930839684be5ac Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Nov 2023 12:20:13 -0800 Subject: [PATCH 1/3] Ensure notes are saved to the action log when licenses are checked in and out --- app/Http/Controllers/Licenses/LicenseCheckinController.php | 2 +- app/Http/Controllers/Licenses/LicenseCheckoutController.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Licenses/LicenseCheckinController.php b/app/Http/Controllers/Licenses/LicenseCheckinController.php index a78b548723..367ff3f1d9 100644 --- a/app/Http/Controllers/Licenses/LicenseCheckinController.php +++ b/app/Http/Controllers/Licenses/LicenseCheckinController.php @@ -101,7 +101,7 @@ class LicenseCheckinController extends Controller // Was the asset updated? if ($licenseSeat->save()) { - event(new CheckoutableCheckedIn($licenseSeat, $return_to, Auth::user(), $request->input('note'))); + event(new CheckoutableCheckedIn($licenseSeat, $return_to, Auth::user(), $request->input('notes'))); if ($backTo == 'user') { return redirect()->route('users.show', $return_to->id)->with('success', trans('admin/licenses/message.checkin.success')); diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.php index ec6b4bbac8..07ca8bbd58 100644 --- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php +++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php @@ -105,7 +105,7 @@ class LicenseCheckoutController extends Controller $licenseSeat->assigned_to = $target->assigned_to; } if ($licenseSeat->save()) { - event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('note'))); + event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('notes'))); return true; } @@ -122,7 +122,7 @@ class LicenseCheckoutController extends Controller $licenseSeat->assigned_to = request('assigned_to'); if ($licenseSeat->save()) { - event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('note'))); + event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('notes'))); return true; } From 4d2790c3f4178eaad631ef3a19e95f925f5351e2 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Nov 2023 13:54:36 -0800 Subject: [PATCH 2/3] Add tests for license checkout notes --- .../Feature/Checkouts/LicenseCheckoutTest.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/Feature/Checkouts/LicenseCheckoutTest.php diff --git a/tests/Feature/Checkouts/LicenseCheckoutTest.php b/tests/Feature/Checkouts/LicenseCheckoutTest.php new file mode 100644 index 0000000000..c1529355bf --- /dev/null +++ b/tests/Feature/Checkouts/LicenseCheckoutTest.php @@ -0,0 +1,65 @@ +superuser()->create(); + $asset = Asset::factory()->create(); + $licenseSeat = LicenseSeat::factory()->create(); + + $this->actingAs($admin) + ->post("/licenses/{$licenseSeat->license->id}/checkout", [ + 'checkout_to_type' => 'asset', + 'assigned_to' => null, + 'asset_id' => $asset->id, + 'notes' => 'oh hi there', + ]) + ->assertRedirect(); + + $this->assertDatabaseHas('action_logs', [ + 'action_type' => 'checkout', + 'target_id' => $asset->id, + 'target_type' => Asset::class, + 'item_id' => $licenseSeat->license->id, + 'item_type' => License::class, + 'note' => 'oh hi there', + ]); + } + + public function testNotesAreStoredInActionLogOnCheckoutToUser() + { + $admin = User::factory()->superuser()->create(); + $licenseSeat = LicenseSeat::factory()->create(); + + $this->actingAs($admin) + ->post("/licenses/{$licenseSeat->license->id}/checkout", [ + 'checkout_to_type' => 'user', + 'assigned_to' => $admin->id, + 'asset_id' => null, + 'notes' => 'oh hi there', + ]) + ->assertRedirect(); + + $this->assertDatabaseHas('action_logs', [ + 'action_type' => 'checkout', + 'target_id' => $admin->id, + 'target_type' => User::class, + 'item_id' => $licenseSeat->license->id, + 'item_type' => License::class, + 'note' => 'oh hi there', + ]); + } +} From 4fb349e3269390c2a88478734b244e433957b927 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Nov 2023 14:04:52 -0800 Subject: [PATCH 3/3] Remove extra assertions --- tests/Feature/Checkouts/LicenseCheckoutTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/Feature/Checkouts/LicenseCheckoutTest.php b/tests/Feature/Checkouts/LicenseCheckoutTest.php index c1529355bf..978fac28f2 100644 --- a/tests/Feature/Checkouts/LicenseCheckoutTest.php +++ b/tests/Feature/Checkouts/LicenseCheckoutTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Checkouts; -use App\Models\Actionlog; use App\Models\Asset; use App\Models\License; use App\Models\LicenseSeat; @@ -26,8 +25,7 @@ class LicenseCheckoutTest extends TestCase 'assigned_to' => null, 'asset_id' => $asset->id, 'notes' => 'oh hi there', - ]) - ->assertRedirect(); + ]); $this->assertDatabaseHas('action_logs', [ 'action_type' => 'checkout', @@ -50,8 +48,7 @@ class LicenseCheckoutTest extends TestCase 'assigned_to' => $admin->id, 'asset_id' => null, 'notes' => 'oh hi there', - ]) - ->assertRedirect(); + ]); $this->assertDatabaseHas('action_logs', [ 'action_type' => 'checkout',