mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Move findLicenseSeatToCheckout back to controller. (#5970)
* Move findLicenseSeatToCheckout back to controller. After discussion, move findLicenseSeatToCheckout method back to controller from form request. Also cleanup one tiny bit more with null coalesce operator (Yay php 7). * Revert Earlier change. $target only exists in the checkoutTo* methods. Need to log the checkout individually in each of those.
This commit is contained in:
parent
b58c77c8b8
commit
248fcfa869
|
@ -56,24 +56,41 @@ class LicenseCheckoutController extends Controller
|
|||
|
||||
public function store(LicenseCheckoutRequest $request, $licenseId, $seatId = null)
|
||||
{
|
||||
$license = License::find($licenseId);
|
||||
if (!$license) {
|
||||
if (!$license = License::find($licenseId)) {
|
||||
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found'));
|
||||
}
|
||||
|
||||
$this->authorize('checkout', $license);
|
||||
|
||||
$licenseSeat = $request->findLicenseSeatToCheckout($license, $seatId);
|
||||
|
||||
$licenseSeat = $this->findLicenseSeatToCheckout($license, $seatId);
|
||||
$licenseSeat->user_id = Auth::id();
|
||||
$checkoutMethod = 'checkoutTo'.ucwords(request('checkout_to_type'));
|
||||
|
||||
$checkoutMethod = 'checkoutTo'.ucwords(request('checkout_to_type'));
|
||||
if ($this->$checkoutMethod($licenseSeat)) {
|
||||
return redirect()->route("licenses.index")->with('success', trans('admin/licenses/message.checkout.success'));
|
||||
}
|
||||
|
||||
return redirect()->route("licenses.index")->with('error', trans('Something went wrong handling this checkout.'));
|
||||
}
|
||||
|
||||
protected function findLicenseSeatToCheckout($license, $seatId)
|
||||
{
|
||||
$licenseSeat = LicenseSeat::find($seatId) ?? $license->freeSeat();
|
||||
|
||||
if (!$licenseSeat) {
|
||||
if ($seatId) {
|
||||
return redirect()->route('licenses.index')->with('error', 'This Seat is not available for checkout.');
|
||||
}
|
||||
return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
|
||||
}
|
||||
|
||||
if(!$licenseSeat->license->is($license)) {
|
||||
return redirect()->route('licenses.index')->with('error', 'The license seat provided does not match the license.');
|
||||
}
|
||||
|
||||
return $licenseSeat;
|
||||
}
|
||||
|
||||
protected function checkoutToAsset($licenseSeat)
|
||||
{
|
||||
if (is_null($target = Asset::find(request('asset_id')))) {
|
||||
|
@ -85,8 +102,7 @@ class LicenseCheckoutController extends Controller
|
|||
if ($target->checkedOutToUser()) {
|
||||
$licenseSeat->assigned_to = $target->assigned_to;
|
||||
}
|
||||
|
||||
if ($licenseSeat->save()) {
|
||||
if ($licenseSeat->save()) {
|
||||
$licenseSeat->logCheckout(request('note'), $target);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -29,25 +29,4 @@ class LicenseCheckoutRequest extends FormRequest
|
|||
'asset_id' => 'required_without:assigned_to',
|
||||
];
|
||||
}
|
||||
|
||||
public function findLicenseSeatToCheckout($license, $seatId)
|
||||
{
|
||||
// This returns null if seatId is null
|
||||
if (!$licenseSeat = LicenseSeat::find($seatId)) {
|
||||
$licenseSeat = $license->freeSeat();
|
||||
}
|
||||
|
||||
if (!$licenseSeat) {
|
||||
if ($seatId) {
|
||||
return redirect()->route('licenses.index')->with('error', 'This Seat is not available for checkout.');
|
||||
}
|
||||
return redirect()->route('licenses.index')->with('error', 'There are no available seats for this license');
|
||||
}
|
||||
|
||||
if(!$licenseSeat->license->is($license)) {
|
||||
return redirect()->route('licenses.index')->with('error', 'The license seat provided does not match the license.');
|
||||
}
|
||||
|
||||
return $licenseSeat;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue