From 8c73a47afb40caea13e9ec3d0f463b09a5d42959 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 15 Jul 2019 15:27:02 -0700 Subject: [PATCH] =?UTF-8?q?Fixed=20#7186=20-=20has=20vs=20filled=20in=20Us?= =?UTF-8?q?er=E2=80=99s=20API=20blanking=20out=20groups=20if=20no=20group?= =?UTF-8?q?=5Fids=20are=20passed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/UsersController.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index ee02f0e4ba..55d8ea0b31 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -260,12 +260,21 @@ class UsersController extends Controller if ($user->save()) { + // Sync group memberships: + // This was changed in Snipe-IT v4.6.x to 4.7, since we upgraded to Laravel 5.5 + // which changes the behavior of has vs filled. + // The $request->has method will now return true even if the input value is an empty string or null. + // A new $request->filled method has was added that provides the previous behavior of the has method. + + // Check if the request has groups passed and has a value if ($request->filled('groups')) { $user->groups()->sync($request->input('groups')); - } else { + // The groups value has been passed but it is null, so we should blank it out + } elseif ($request->has('groups')) { $user->groups()->sync(array()); } + return response()->json(Helper::formatStandardApiResponse('success', (new UsersTransformer)->transformUser($user), trans('admin/users/message.success.update'))); }