Revert asset-checkout-different validation.

This was causing issues when trying to check an item out to a user or a
location because of the way laravel handles validation.

Instead, rely on the exception check we had in the controller.  I moved
this exception up to the model checkout method so that it would work
for anywhere that that method was called, even if it avoided the
controller.
This commit is contained in:
Daniel Meltzer 2020-04-29 10:59:00 -04:00
parent c34650458f
commit f8d18a8eb0
No known key found for this signature in database
GPG key ID: 91C5C7B09A5B1CA0
3 changed files with 6 additions and 4 deletions

View file

@ -62,9 +62,7 @@ class AssetCheckoutController extends Controller
$admin = Auth::user();
$target = $this->determineCheckoutTarget($asset);
if ($asset->is($target)) {
throw new CheckoutNotAllowed('You cannot check an asset out to itself.');
}
$asset = $this->updateAssetLocation($asset, $target);
$checkout_at = date("Y-m-d H:i:s");

View file

@ -23,7 +23,7 @@ class AssetCheckoutRequest extends Request
{
$rules = [
"assigned_user" => 'required_without_all:assigned_asset,assigned_location',
"assigned_asset" => 'required_without_all:assigned_user,assigned_location|different:'.$this->id,
"assigned_asset" => 'required_without_all:assigned_user,assigned_location',
"assigned_location" => 'required_without_all:assigned_user,assigned_asset',
"checkout_to_type" => 'required|in:asset,location,user'
];

View file

@ -3,6 +3,7 @@ namespace App\Models;
use App\Events\AssetCheckedOut;
use App\Events\CheckoutableCheckedOut;
use App\Exceptions\CheckoutNotAllowed;
use App\Http\Traits\UniqueSerialTrait;
use App\Http\Traits\UniqueUndeletedTrait;
use App\Models\Traits\Acceptable;
@ -271,6 +272,9 @@ class Asset extends Depreciable
if (!$target) {
return false;
}
if ($this->is($target)) {
throw new CheckoutNotAllowed('You cannot check an asset out to itself.');
}
if ($expected_checkin) {
$this->expected_checkin = $expected_checkin;