Fixed regression: missing restore option for assets via API

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2022-06-09 17:17:38 -07:00
parent 166f526302
commit 4c11041477
2 changed files with 31 additions and 11 deletions

View file

@ -714,12 +714,20 @@ class AssetsController extends Controller
* @since [v5.1.18] * @since [v5.1.18]
* @return JsonResponse * @return JsonResponse
*/ */
public function restore($assetId = null) public function restore(Request $request, $assetId = null)
{ {
// Get asset information // Get asset information
$asset = Asset::withTrashed()->find($assetId); $asset = Asset::withTrashed()->find($assetId);
$this->authorize('delete', $asset); $this->authorize('delete', $asset);
if (isset($asset->id)) { if (isset($asset->id)) {
if ($asset->deleted_at=='') {
$message = 'Asset was not deleted. No data was changed.';
} else {
$message = trans('admin/hardware/message.restore.success');
// Restore the asset // Restore the asset
Asset::withTrashed()->where('id', $assetId)->restore(); Asset::withTrashed()->where('id', $assetId)->restore();
@ -729,8 +737,9 @@ class AssetsController extends Controller
$logaction->created_at = date("Y-m-d H:i:s"); $logaction->created_at = date("Y-m-d H:i:s");
$logaction->user_id = Auth::user()->id; $logaction->user_id = Auth::user()->id;
$logaction->logaction('restored'); $logaction->logaction('restored');
}
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.restore.success'))); return response()->json(Helper::formatStandardApiResponse('success', (new AssetsTransformer)->transformAsset($asset, $request), $message));
} }

View file

@ -483,9 +483,20 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:'.config('app.
'checkout' 'checkout'
] ]
)->name('api.asset.checkout'); )->name('api.asset.checkout');
Route::post('{asset_id}/restore',
[
Api\AssetsController::class,
'restore'
]
)->name('api.assets.restore');
}); });
Route::resource('hardware', Route::resource('hardware',
Api\AssetsController::class, Api\AssetsController::class,
['names' => ['names' =>