From 03b0268dc295282df062942232ba1da4d20cb5c0 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 1 Jun 2024 03:00:45 +0100 Subject: [PATCH] Fixed typo Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 31 ++++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 5a37c50e1b..c2c18748b0 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -79,6 +79,10 @@ class UsersController extends Controller ->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'managesUsers as manages_users_count', 'managedLocations as manages_locations_count'); + if ($request->filled('search') != '') { + $users = $users->TextSearch($request->input('search')); + } + if ($request->filled('activated')) { $users = $users->where('users.activated', '=', $request->input('activated')); } @@ -201,8 +205,12 @@ class UsersController extends Controller if ($request->filled('location_id') != '') { $users = $users->UserLocation($request->input('location_id'), $request->input('search')); - } else { - $users = $users->TextSearch($request->input('search')); + } + + if (($request->filled('deleted')) && ($request->input('deleted') == 'true')) { + $users = $users->onlyTrashed(); + } elseif (($request->filled('all')) && ($request->input('all') == 'true')) { + $users = $users->withTrashed(); } $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; @@ -254,7 +262,7 @@ class UsersController extends Controller 'licenses_count', 'consumables_count', 'accessories_count', - 'manages_user_count', + 'manages_users_count', 'manages_locations_count', 'phone', 'address', @@ -274,16 +282,12 @@ class UsersController extends Controller 'website', ]; - $sort = in_array($request->get('sort'), $allowed_columns) ? $request->get('sort') : 'first_name'; + $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'first_name'; $users = $users->orderBy($sort, $order); break; } - if (($request->filled('deleted')) && ($request->input('deleted') == 'true')) { - $users = $users->onlyTrashed(); - } elseif (($request->filled('all')) && ($request->input('all') == 'true')) { - $users = $users->withTrashed(); - } + // Apply companyable scope $users = Company::scopeCompanyables($users); @@ -551,6 +555,15 @@ class UsersController extends Controller return response()->json(Helper::formatStandardApiResponse('error', null, 'This user still has ' . $user->managedLocations()->count() . ' locations that they manage.')); } + + + if (($user->managesUsers()) && ($user->managesUsers()->count() > 0)) { + + return response()->json(Helper::formatStandardApiResponse('error', null, 'This user still has ' . $user->managesUsers()->count() . ' users that they manage.')); + } + + + if ($user->delete()) { // Remove the user's avatar if they have one