mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 22:19:41 -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,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));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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' =>
|
||||||
|
|
Loading…
Reference in a new issue