From be8438ee5a7c6cc6404c73f8aaf2216976323045 Mon Sep 17 00:00:00 2001 From: Craig Williams Date: Tue, 8 Feb 2022 16:57:36 +0000 Subject: [PATCH] Handle the case where all roles are removed from a user --- app/sprinkles/admin/src/Controller/UserController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/sprinkles/admin/src/Controller/UserController.php b/app/sprinkles/admin/src/Controller/UserController.php index 1acf4af06..d880e75b4 100644 --- a/app/sprinkles/admin/src/Controller/UserController.php +++ b/app/sprinkles/admin/src/Controller/UserController.php @@ -1322,11 +1322,15 @@ public function updateField(Request $request, Response $response, array $args) // Get PUT parameters: value $put = $request->getParsedBody(); - // Make sure data is part of $_PUT data + // Make sure data is part of $_PUT data, default to empty value if sensible, otherwise error if (isset($put[$fieldName])) { $fieldData = $put[$fieldName]; } else { - throw new BadRequestException(); + if ($fieldName == 'roles') { + $fieldData = []; + } else { + throw new BadRequestException(); + } } // Create and validate key -> value pair