Skip to content

Commit

Permalink
Revert asset-checkout-different validation.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmeltzer committed Apr 29, 2020
1 parent c346504 commit f8d18a8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 1 addition & 3 deletions app/Http/Controllers/Assets/AssetCheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public function store(AssetCheckoutRequest $request, $assetId)
$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");
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/AssetCheckoutRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function rules()
{
$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'
];
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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;
Expand Down Expand Up @@ -271,6 +272,9 @@ public function checkOut($target, $admin = null, $checkout_at = null, $expected_
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;
Expand Down

0 comments on commit f8d18a8

Please sign in to comment.