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,23 +714,32 @@ 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)) {
// Restore the asset
Asset::withTrashed()->where('id', $assetId)->restore();
$logaction = new Actionlog(); if ($asset->deleted_at=='') {
$logaction->item_type = Asset::class; $message = 'Asset was not deleted. No data was changed.';
$logaction->item_id = $asset->id;
$logaction->created_at = date("Y-m-d H:i:s");
$logaction->user_id = Auth::user()->id;
$logaction->logaction('restored');
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.restore.success'))); } else {
$message = trans('admin/hardware/message.restore.success');
// Restore the asset
Asset::withTrashed()->where('id', $assetId)->restore();
$logaction = new Actionlog();
$logaction->item_type = Asset::class;
$logaction->item_id = $asset->id;
$logaction->created_at = date("Y-m-d H:i:s");
$logaction->user_id = Auth::user()->id;
$logaction->logaction('restored');
}
return response()->json(Helper::formatStandardApiResponse('success', (new AssetsTransformer)->transformAsset($asset, $request), $message));
} }

View file

@ -483,7 +483,18 @@ 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',