From c1a35920597f0fc2fcafca1d7a63681ffbc3c01d Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 10 Jun 2016 08:29:43 -0700 Subject: [PATCH] Fixes #2130 --- app/Http/Controllers/ViewAssetsController.php | 38 ++++++++++++++----- app/Http/routes.php | 2 +- app/Models/Asset.php | 4 +- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index b25c531e07..984c0a0c74 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -6,6 +6,7 @@ use App\Models\Actionlog; use App\Models\Asset; use App\Models\Company; use App\Models\Consumable; +use App\Models\Component; use App\Models\Location; use App\Models\Setting; use App\Models\User; @@ -142,11 +143,12 @@ class ViewAssetsController extends Controller public function getAcceptAsset($logID = null) { - if (is_null($findlog = Actionlog::find($logID))) { - // Redirect to the asset management page - return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist')); + if (!$findlog = DB::table('asset_logs')->where('id','=',$logID)->first()) { + echo 'no record'; + //return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist')); } + $user = Auth::user(); if ($user->id != $findlog->checkedout_to) { @@ -163,6 +165,12 @@ class ViewAssetsController extends Controller // accessories } elseif ($findlog->accessory_id!='') { $item = Accessory::find($findlog->accessory_id); + // consumable + } elseif ($findlog->consumable_id!='') { + $item = Consumable::find($findlog->consumable_id); + // components + } elseif ($findlog->component_id!='') { + $item = Component::find($findlog->component_id); } // Check if the asset exists @@ -181,16 +189,11 @@ class ViewAssetsController extends Controller { // Check if the asset exists - if (is_null($findlog = Actionlog::find($logID))) { + if (is_null($findlog = DB::table('asset_logs')->where('id','=',$logID)->first())) { // Redirect to the asset management page return redirect()->to('account/view-assets')->with('error', trans('admin/hardware/message.does_not_exist')); } - - // NOTE: make sure the global scope is applied - $is_unauthorized = is_null(Actionlog::where('id', '=', $logID)->first()); - if ($is_unauthorized) { - return redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions')); - } + if ($findlog->accepted_id!='') { // Redirect to the asset management page @@ -236,13 +239,28 @@ class ViewAssetsController extends Controller } elseif (($findlog->asset_id!='') && ($findlog->asset_type=='software')) { $logaction->asset_id = $findlog->asset_id; $logaction->accessory_id = null; + $logaction->component_id = null; $logaction->asset_type = 'software'; // accessories } elseif ($findlog->accessory_id!='') { $logaction->asset_id = null; + $logaction->component_id = null; $logaction->accessory_id = $findlog->accessory_id; $logaction->asset_type = 'accessory'; + // accessories + } elseif ($findlog->consumable_id!='') { + $logaction->asset_id = null; + $logaction->accessory_id = null; + $logaction->component_id = null; + $logaction->consumable_id = $findlog->consumable_id; + $logaction->asset_type = 'consumable'; + } elseif ($findlog->component_id!='') { + $logaction->asset_id = null; + $logaction->accessory_id = null; + $logaction->consumable_id = null; + $logaction->component_id = $findlog->component_id; + $logaction->asset_type = 'component'; } $logaction->checkedout_to = $findlog->checkedout_to; diff --git a/app/Http/routes.php b/app/Http/routes.php index 6ffa1d0032..2001d25569 100755 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -726,7 +726,7 @@ Route::group([ 'prefix' => 'account', 'middleware' => ['web', 'auth']], function ); # Account Dashboard - Route::get('/', [ 'as' => 'account', 'uses' => 'ProfileController@getDashboard' ]); + Route::get('/', [ 'as' => 'account', 'uses' => 'ViewAssetsController@getIndex' ]); }); diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 3a48b9df6b..9cf7b262a3 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -97,10 +97,10 @@ class Asset extends Depreciable if ($this->save()) { // $action, $admin, $user, $expected_checkin = null, $note = null, $checkout_at = null - $log_id = $this->createLogRecord('checkout', $this, $admin, $user, $expected_checkin, $note, $checkout_at); + $log = $this->createLogRecord('checkout', $this, $admin, $user, $expected_checkin, $note, $checkout_at); if ((($this->requireAcceptance()=='1') || ($this->getEula())) && ($user->email!='')) { - $this->checkOutNotifyMail($log_id, $user, $checkout_at, $expected_checkin, $note); + $this->checkOutNotifyMail($log->id, $user, $checkout_at, $expected_checkin, $note); } if ($settings->slack_endpoint) {