Skip to content

Commit

Permalink
Fixed #7186 - has vs filled in User’s API blanking out groups if no g…
Browse files Browse the repository at this point in the history
…roup_ids are passed
  • Loading branch information
snipe committed Jul 15, 2019
1 parent f82ffe3 commit 8c73a47
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/Http/Controllers/Api/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,21 @@ public function update(SaveUserRequest $request, $id)

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')));
}

Expand Down

0 comments on commit 8c73a47

Please sign in to comment.