mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 23:54:12 -08:00
Add restore to users api endpoint
This commit is contained in:
parent
9f3b63387a
commit
20f7fe1ecc
|
@ -474,4 +474,28 @@ class UsersController extends Controller
|
||||||
{
|
{
|
||||||
return (new UsersTransformer)->transformUser($request->user());
|
return (new UsersTransformer)->transformUser($request->user());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore a soft-deleted user.
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @param int $userId
|
||||||
|
* @since [v6.0.0]
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function restore($userId = null)
|
||||||
|
{
|
||||||
|
// Get asset information
|
||||||
|
$user = User::withTrashed()->find($userId);
|
||||||
|
$this->authorize('delete', $user);
|
||||||
|
if (isset($user->id)) {
|
||||||
|
// Restore the user
|
||||||
|
User::withTrashed()->where('id', $userId)->restore();
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/users/message.success.restored')));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_exists')), 200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -896,6 +896,13 @@ Route::group(['prefix' => 'v1', 'middleware' => 'api'], function () {
|
||||||
]
|
]
|
||||||
)->name('api.users.uploads');
|
)->name('api.users.uploads');
|
||||||
|
|
||||||
|
Route::post('{user}/restore',
|
||||||
|
[
|
||||||
|
Api\UsersController::class,
|
||||||
|
'restore'
|
||||||
|
]
|
||||||
|
)->name('api.users.restore');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::resource('users',
|
Route::resource('users',
|
||||||
|
|
Loading…
Reference in a new issue