A free open source IT asset/license management system
Moved gates higher, switch to RMB for accessories
snipe63e62cde1b34
diff --git a/app/Http/Controllers/Accessories/AccessoriesController.php b/app/Http/Controllers/Accessories/AccessoriesController.phpindex 12504be466..c84d11fae2 100755--- a/app/Http/Controllers/Accessories/AccessoriesController.php+++ b/app/Http/Controllers/Accessories/AccessoriesController.php@@ -114,7 +114,8 @@ class AccessoriesController extends Controller*/public function edit(Accessory $accessory) : View | RedirectResponse{- $this->authorize('update', Accessory::class);+ $this->authorize('update', $accessory);+ session()->put('back_url', url()->previous());return view('accessories.edit')->with('item', $accessory)->with('category_type', 'accessory');}@@ -128,7 +129,7 @@ class AccessoriesController extends Controllerpublic function getClone(Accessory $accessory) : View | RedirectResponse{- $this->authorize('create', Accessory::class);+ $this->authorize('create', $accessory);$cloned = clone $accessory;$accessory_to_clone = $accessory;$cloned->id = null;@@ -149,9 +150,9 @@ class AccessoriesController extends Controller*/public function update(ImageUploadRequest $request, Accessory $accessory) : RedirectResponse{- if ($accessory = Accessory::withCount('checkouts as checkouts_count')->find($accessory->id)) {+ $this->authorize('update', $accessory);- $this->authorize($accessory);+ if ($accessory = Accessory::withCount('checkouts as checkouts_count')->find($accessory->id)) {$validator = Validator::make($request->all(), ["qty" => "required|numeric|min:$accessory->checkouts_count"@@ -163,8 +164,6 @@ class AccessoriesController extends Controller->withInput();}--// Update the accessory data$accessory->name = request('name');$accessory->location_id = request('location_id');@@ -182,7 +181,7 @@ class AccessoriesController extends Controller$accessory = $request->handleImages($accessory);- if($request->input('redirect_option') === 'back'){+ if ($request->input('redirect_option') === 'back'){session()->put(['redirect_option' => 'index']);} else {session()->put(['redirect_option' => $request->input('redirect_option')]);@@ -211,7 +210,7 @@ class AccessoriesController extends Controllerreturn redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.not_found'));}- $this->authorize($accessory);+ $this->authorize('delete', $accessory);if ($accessory->checkouts_count > 0) {@@ -243,11 +242,9 @@ class AccessoriesController extends Controller*/public function show(Accessory $accessory) : View | RedirectResponse{+ $this->authorize('view', $accessory);$accessory->loadCount('checkouts as checkouts_count');-$accessory->load(['adminuser' => fn($query) => $query->withTrashed()]);-- $this->authorize('view', $accessory);return view('accessories.view', compact('accessory'));}}diff --git a/app/Http/Controllers/Accessories/AccessoryCheckinController.php b/app/Http/Controllers/Accessories/AccessoryCheckinController.phpindex 1dbc87a3e5..11a3f9d6fc 100644--- a/app/Http/Controllers/Accessories/AccessoryCheckinController.php+++ b/app/Http/Controllers/Accessories/AccessoryCheckinController.php@@ -29,6 +29,7 @@ class AccessoryCheckinController extends Controller}$accessory = Accessory::find($accessory_user->accessory_id);+ $this->authorize('checkin', $accessory);//based on what the accessory is checked out to the target redirect option will be displayed accordingly.$target_option = match ($accessory_user->assigned_type) {@@ -36,7 +37,7 @@ class AccessoryCheckinController extends Controller'App\Models\Location' => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.location')]),default => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.user')]),};- $this->authorize('checkin', $accessory);+return view('accessories/checkin', compact('accessory', 'target_option'))->with('backto', $backto);@@ -57,6 +58,7 @@ class AccessoryCheckinController extends Controller}$accessory = Accessory::find($accessory_checkout->accessory_id);+ $this->authorize('checkin', $accessory);session()->put('checkedInFrom', $accessory_checkout->assigned_to);session()->put('checkout_to_type', match ($accessory_checkout->assigned_type) {@@ -65,7 +67,7 @@ class AccessoryCheckinController extends Controller'App\Models\Asset' => 'asset',});- $this->authorize('checkin', $accessory);+$checkin_hours = date('H:i:s');$checkin_at = date('Y-m-d H:i:s');if ($request->filled('checkin_at')) {diff --git a/app/Http/Controllers/Accessories/AccessoryCheckoutController.php b/app/Http/Controllers/Accessories/AccessoryCheckoutController.phpindex f014a6995c..a31ba7ab54 100644--- a/app/Http/Controllers/Accessories/AccessoryCheckoutController.php+++ b/app/Http/Controllers/Accessories/AccessoryCheckoutController.php@@ -27,31 +27,24 @@ class AccessoryCheckoutController extends Controller* @author [A. Gianotto] [<[email protected]>]* @param int $id*/- public function create($id) : View | RedirectResponse+ public function create(Accessory $accessory) : View | RedirectResponse{- if ($accessory = Accessory::withCount('checkouts as checkouts_count')->find($id)) {-- $this->authorize('checkout', $accessory);-- if ($accessory->category) {- // Make sure there is at least one available to checkout- if ($accessory->numRemaining() <= 0){- return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkout.unavailable'));- }+ $this->authorize('checkout', $accessory);- // Return the checkout view- return view('accessories/checkout', compact('accessory'));+ if ($accessory->category) {+ // Make sure there is at least one available to checkout+ if ($accessory->numRemaining() <= 0){+ return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkout.unavailable'));}- // Invalid category- return redirect()->route('accessories.edit', ['accessory' => $accessory->id])- ->with('error', trans('general.invalid_item_category_single', ['type' => trans('general.accessory')]));-+ // Return the checkout view+ return view('accessories/checkout', compact('accessory'));}- // Not found- return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.not_found'));+ // Invalid category+ return redirect()->route('accessories.edit', ['accessory' => $accessory->id])+ ->with('error', trans('general.invalid_item_category_single', ['type' => trans('general.accessory')]));}diff --git a/routes/web/accessories.php b/routes/web/accessories.phpindex 33b986f2fd..15b89572a0 100644--- a/routes/web/accessories.php+++ b/routes/web/accessories.php@@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Route;*/Route::group(['prefix' => 'accessories', 'middleware' => ['auth']], function () {Route::get(- '{accessoryID}/checkout',+ '{accessory}/checkout',[Accessories\AccessoryCheckoutController::class, 'create'])->name('accessories.checkout.show');@@ -31,7 +31,7 @@ Route::group(['prefix' => 'accessories', 'middleware' => ['auth']], function ()[Accessories\AccessoriesController::class, 'getClone'])->name('clone/accessories');- Route::post('{accessoryId}/clone',+ Route::post('{accessory}/clone',[Accessories\AccessoriesController::class, 'postCreate']);