Skip to content

A free open source IT asset/license management system

Fix acceptance cleanup on user item transfer

Marcus Moore635f1a640f6e
diff --git a/app/Http/Controllers/Users/UserItemTransferController.php b/app/Http/Controllers/Users/UserItemTransferController.php
index 93bfd2bc02..209ded0c19 100644
--- a/app/Http/Controllers/Users/UserItemTransferController.php
+++ b/app/Http/Controllers/Users/UserItemTransferController.php
@@ -10,7 +10,6 @@ use App\Models\Accessory;
use App\Models\AccessoryCheckout;
use App\Models\Asset;
use App\Models\CheckoutAcceptance;
-use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\User;
use Illuminate\Contracts\View\View;
@@ -224,13 +223,9 @@ class UserItemTransferController extends Controller
{
$source = $checkout->assignedTo;
- CheckoutAcceptance::pending()
- ->where('checkoutable_type', Accessory::class)
- ->where('checkoutable_id', $accessory->id)
- ->where('assigned_to_id', $checkout->assigned_to)
- ->get()
- ->each(fn ($a) => $a->delete());
-
+ // You might think you need to clean up acceptances here but that
+ // is going to be handled in the CheckoutableListener that
+ // is run when the event below is fired.
$checkout->delete();
event(new CheckoutableCheckedIn($accessory, $source, auth()->user(), $note, date('Y-m-d H:i:s')));
@@ -253,8 +248,8 @@ class UserItemTransferController extends Controller
private function transferLicenseSeat(LicenseSeat $seat, User $source, User $target, ?string $note): void
{
CheckoutAcceptance::pending()
- ->where('checkoutable_type', License::class)
- ->where('checkoutable_id', $seat->license_id)
+ ->where('checkoutable_type', LicenseSeat::class)
+ ->where('checkoutable_id', $seat->id)
->where('assigned_to_id', $source->id)
->get()
->each(fn ($a) => $a->delete());
diff --git a/tests/Feature/Users/TransferUserItemsAcceptanceCleanupTest.php b/tests/Feature/Users/TransferUserItemsAcceptanceCleanupTest.php
index b7b91ad34d..557b4ac9dc 100644
--- a/tests/Feature/Users/TransferUserItemsAcceptanceCleanupTest.php
+++ b/tests/Feature/Users/TransferUserItemsAcceptanceCleanupTest.php
@@ -18,9 +18,9 @@ class TransferUserItemsAcceptanceCleanupTest extends TestCase
{
parent::setUp();
- // With every channel off the listener returns before its own
- // pending-delete, so these tests exercise the controller's inline
- // cleanup rather than the listener backstop.
+ // Every channel off: clearing the acceptance request is part of
+ // checking the item in, not of notifying anyone, so it must still
+ // happen on an install that notifies nobody. That is the bug pinned here.
$this->settings->disableSlackWebhook()
->disableAdminCC()
->disableAdminCCAlways();
@@ -37,7 +37,7 @@ class TransferUserItemsAcceptanceCleanupTest extends TestCase
]);
$seat = LicenseSeat::factory()->assignedToUser($source)->create(['license_id' => $license->id]);
- $this->assertFalse((bool) $license->checkin_email(), 'Checkin email must be off, or the listener backstop deletes the pending and these tests pass without exercising the inline cleanup.');
+ $this->assertFalse((bool) $license->checkin_email(), 'Checkin email must be off, or this stops proving cleanup happens with notifications disabled.');
// A real seat acceptance is keyed to the SEAT — LicenseSeat::class plus
// the seat's own id — which is what CreateCheckoutAcceptanceAction
@@ -70,7 +70,7 @@ class TransferUserItemsAcceptanceCleanupTest extends TestCase
$transferredSeat = LicenseSeat::factory()->assignedToUser($source)->create(['license_id' => $license->id]);
$retainedSeat = LicenseSeat::factory()->assignedToUser($source)->create(['license_id' => $license->id]);
- $this->assertFalse((bool) $license->checkin_email(), 'Checkin email must be off, or the listener backstop deletes the pending and these tests pass without exercising the inline cleanup.');
+ $this->assertFalse((bool) $license->checkin_email(), 'Checkin email must be off, or this stops proving cleanup happens with notifications disabled.');
// The source user holds two seats of the same license and only one of
// them is transferred. The cleanup has to key on the seat, not on the
@@ -101,7 +101,7 @@ class TransferUserItemsAcceptanceCleanupTest extends TestCase
'qty' => 5,
]);
- $this->assertFalse((bool) $accessory->checkin_email(), 'Checkin email must be off, or the listener backstop deletes the pending and these tests pass without exercising the inline cleanup.');
+ $this->assertFalse((bool) $accessory->checkin_email(), 'Checkin email must be off, or this stops proving cleanup happens with notifications disabled.');
$sourceCheckout = $accessory->checkouts()->where('assigned_to', $source->id)->firstOrFail();
@@ -139,7 +139,7 @@ class TransferUserItemsAcceptanceCleanupTest extends TestCase
]),
]);
- $this->assertFalse((bool) $asset->fresh()->checkin_email(), 'Checkin email must be off, or the listener backstop deletes the pending and these tests pass without exercising the inline cleanup.');
+ $this->assertFalse((bool) $asset->fresh()->checkin_email(), 'Checkin email must be off, or this stops proving cleanup happens with notifications disabled.');
$acceptance = CheckoutAcceptance::factory()->pending()->create([
'checkoutable_id' => $asset->id,