mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Fixed regression: missing restore option for assets via API
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
166f526302
commit
4c11041477
|
@ -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));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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',
|
||||||
|
|
Loading…
Reference in a new issue