diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index ff7d9ef86295..f2529e190bd0 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -474,4 +474,26 @@ public function getCurrentUserInfo(Request $request) { return (new UsersTransformer)->transformUser($request->user()); } + + /** + * Restore a soft-deleted user. + * + * @author [E. Taylor] [] + * @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); + } } diff --git a/routes/api.php b/routes/api.php index 6f8d22a4d9a6..2d3731b7ca8f 100644 --- a/routes/api.php +++ b/routes/api.php @@ -896,6 +896,13 @@ ] )->name('api.users.uploads'); + Route::post('{user}/restore', + [ + Api\UsersController::class, + 'restore' + ] + )->name('api.users.restore'); + }); Route::resource('users',