Merge pull request #10111 from Delta5/add-restore-user-api-endpoint

Added restore functionality to user API
This commit is contained in:
snipe 2021-09-21 20:05:52 -07:00 committed by GitHub
commit df1b1bc972
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View file

@ -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 [E. Taylor] [<dev@evantaylor.name>]
* @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')));
}
$id = $userId;
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_not_found', compact('id'))), 200);
}
} }

View file

@ -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',