From 30d68309a907ccf37ca596d974eecc5f6bd3c597 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 10 Nov 2020 05:06:47 -0800 Subject: [PATCH] =?UTF-8?q?Add=20ability=20to=20checkout=20an=20asset=20if?= =?UTF-8?q?=20the=20user=20it=E2=80=99s=20assigned=5Fto=20isn=E2=80=99t=20?= =?UTF-8?q?valid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This would only happen if a merge-users went wonky --- app/Models/Asset.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 9af62593d7..1492f5a443 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -232,7 +232,10 @@ class Asset extends Depreciable } /** - * Determines if an asset is available for checkout + * Determines if an asset is available for checkout. + * This checks to see if the it's checked out to an invalid (deleted) user + * OR if the assigned_to and deleted_at fields on the asset are empty AND + * that the status is deployable * * @author [A. Gianotto] [] * @since [v3.0] @@ -241,9 +244,10 @@ class Asset extends Depreciable public function availableForCheckout() { if ( - (empty($this->assigned_to)) && + (!$this->assignedTo) || + ((empty($this->assigned_to)) && (empty($this->deleted_at)) && - (($this->assetstatus) && ($this->assetstatus->deployable == 1))) + (($this->assetstatus) && ($this->assetstatus->deployable == 1)))) { return true; } @@ -424,7 +428,7 @@ class Asset extends Depreciable */ public function assignedTo() { - return $this->morphTo('assigned', 'assigned_type', 'assigned_to'); + return $this->morphTo('assigned', 'assigned_type', 'assigned_to')->withTrashed(); } /**