A free open source IT asset/license management system
Merge branch 'develop' into bug/sc-24884
Spencer Long64be353156e9
diff --cc app/Http/Controllers/Api/AssetsController.phpindex 721c6154ac,f0ac97b7f9..948b291ca4--- a/app/Http/Controllers/Api/AssetsController.php+++ b/app/Http/Controllers/Api/AssetsController.php@@@ -713,34 -706,39 +706,33 @@@ class AssetsController extends Controll}}}--+ if ($asset->save()) {+ if (($request->filled('assigned_user')) && ($target = User::find($request->get('assigned_user')))) {+ $location = $target->location_id;+ } elseif (($request->filled('assigned_asset')) && ($target = Asset::find($request->get('assigned_asset')))) {+ $location = $target->location_id;++ Asset::where('assigned_type', \App\Models\Asset::class)->where('assigned_to', $id)+ ->update(['location_id' => $target->location_id]);+ } elseif (($request->filled('assigned_location')) && ($target = Location::find($request->get('assigned_location')))) {+ $location = $target->id;+ }- if ($asset->save()) {- if (($request->filled('assigned_user')) && ($target = User::find($request->get('assigned_user')))) {- $location = $target->location_id;- } elseif (($request->filled('assigned_asset')) && ($target = Asset::find($request->get('assigned_asset')))) {- $location = $target->location_id;- Asset::where('assigned_type', Asset::class)->where('assigned_to', $asset->id)- ->update(['location_id' => $target->location_id]);- } elseif (($request->filled('assigned_location')) && ($target = Location::find($request->get('assigned_location')))) {- $location = $target->id;- }-- if (isset($target)) {- $asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), '', 'Checked out on asset update',- e($request->get('name')), $location);- }+ if (isset($target)) {+ $asset->checkOut($target, auth()->user(), date('Y-m-d H:i:s'), '', 'Checked out on asset update', e($request->get('name')), $location);+ }- if ($asset->image) {- $asset->image = $asset->getImageUrl();- }+ if ($asset->image) {+ $asset->image = $asset->getImageUrl();+ }- if ($problems_updating_encrypted_custom_fields) {- return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.encrypted_warning')));- } else {- return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.success')));- }+ if ($problems_updating_encrypted_custom_fields) {+ return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.encrypted_warning')));+ } else {+ return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.success')));}-- return response()->json(Helper::formatStandardApiResponse('error', null, $asset->getErrors()), 200);}-- return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);+ return response()->json(Helper::formatStandardApiResponse('error', null, $asset->getErrors()), 200);}diff --cc database/factories/LocationFactory.phpindex 94c0efe966,abd773010e..3aa0577bd8--- a/database/factories/LocationFactory.php+++ b/database/factories/LocationFactory.php@@@ -25,9 -25,13 +25,19 @@@ class LocationFactory extends Factor'image' => rand(1, 9).'.jpg',];}--++++ // one of these can eventuall go away - left temporarily for conflict resolution+ public function deleted(): self+ {+ return $this->state(['deleted_at' => $this->faker->dateTime()]);+ }+++ public function deletedLocation()+ {+ return $this->state(function () {+ return [+ 'deleted_at' => $this->faker->dateTime(),+ ];+ });+ }}diff --cc routes/api.phpindex f18aa41c33,5f122b2a18..b5311aa982--- a/routes/api.php+++ b/routes/api.php@@@ -543,42 -544,37 +543,41 @@@ Route::group(['prefix' => 'v1', 'middle'restore'])->name('api.assets.restore');- Route::post('{asset_id}/files',- [- Api\AssetFilesController::class,- 'store'- ]- )->name('api.assets.files');-- Route::get('{asset_id}/files',- [- Api\AssetFilesController::class,- 'list'- ]- )->name('api.assets.files');+ Route::post('{asset_id}/files',+ [+ Api\AssetFilesController::class,+ 'store'+ ]+ )->name('api.assets.files.store');- Route::get('{asset_id}/file/{file_id}',- [- Api\AssetFilesController::class,- 'show'- ]- )->name('api.assets.file');+ Route::get('{asset_id}/files',+ [+ Api\AssetFilesController::class,+ 'list'+ ]+ )->name('api.assets.files.index');- Route::delete('{asset_id}/file/{file_id}',- [- Api\AssetFilesController::class,- 'destroy'- ]- )->name('api.assets.file');+ Route::get('{asset_id}/file/{file_id}',+ [+ Api\AssetFilesController::class,+ 'show'+ ]+ )->name('api.assets.files.show');+ Route::delete('{asset_id}/file/{file_id}',+ [+ Api\AssetFilesController::class,+ 'destroy'+ ]+ )->name('api.assets.files.destroy');-});- Route::resource('hardware',+ // pulling this out of resource route group to begin normalizing for route-model binding.+ // this would probably keep working with the resource route group, but the general practice is for+ // the model name to be the parameter - and i think it's a good differentiation in the code while we convert the others.+ Route::patch('/hardware/{asset}', [Api\AssetsController::class, 'update'])->name('api.assets.update');++ Route::resource('hardware',Api\AssetsController::class,['names' => ['index' => 'api.assets.index',