From c8b4f7452a4f113501a8a0ee50b2c8987e00d9ac Mon Sep 17 00:00:00 2001 From: avsdev-cw Date: Mon, 10 Jan 2022 15:55:16 +0000 Subject: [PATCH] Foreign Key constraint fails when an admin attempts to create a new user Back in 2019 a PR was approved to allow "No Group". It looks like the ability for admins to create users without a group was overlooked. --- app/sprinkles/admin/src/Controller/UserController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/sprinkles/admin/src/Controller/UserController.php b/app/sprinkles/admin/src/Controller/UserController.php index 1acf4af06..15a2f99bc 100644 --- a/app/sprinkles/admin/src/Controller/UserController.php +++ b/app/sprinkles/admin/src/Controller/UserController.php @@ -136,6 +136,11 @@ public function create(Request $request, Response $response, array $args) $data['group_id'] = $currentUser->group_id; } + // 0 maps to "No group", database requires a NULL to avoid issues with foreign keys + if (isset($data['group_id']) && $data['group_id'] == 0) { + $data['group_id'] = null; + } + $data['flag_verified'] = 1; if (!isset($data['password'])) { // Set password as empty on initial creation. We will then send email so new user can set it themselves via a verification token