Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create a user without a group #1273

Open
interactiveRob opened this issue Oct 3, 2024 · 4 comments
Open

Unable to create a user without a group #1273

interactiveRob opened this issue Oct 3, 2024 · 4 comments

Comments

@interactiveRob
Copy link

interactiveRob commented Oct 3, 2024

Affected sprinkle or package

userfrosting/admin

UserFrosting or package Version

5.0.0

Debug Data

UserFrosting Environnement Information
======================================

 -------------------- -----------------------
  Framework version    5.0.0
  OS Name              Linux
  Main Sprinkle Path   /app/code/_server/../
  Environment mode
  PHP Version          8.2.19
  Node Version         v18.20.3
  NPM Version          10.7.0
 -------------------- -----------------------


Loaded Sprinkles
================

 ------------------ --------------------------------------- -------------------------------------------------------
  Sprinkle           Namespace                               Path                                               
 ------------------ --------------------------------------- -------------------------------------------------------
  Core Sprinkle      UserFrosting\Sprinkle\Core\Core         /app/vendor/userfrosting/sprinkle-core/app/src/../ 
  Account Sprinkle   UserFrosting\Sprinkle\Account\Account   /app/vendor/userfrosting/sprinkle-account/app/src/../
  AdminLTE Theme     UserFrosting\Theme\AdminLTE\AdminLTE    /app/vendor/userfrosting/theme-adminlte/app/src/../
  Admin Sprinkle     UserFrosting\Sprinkle\Admin\Admin       /app/vendor/userfrosting/sprinkle-admin/app/src/../
  Finance Fair       UserFrosting\App\Barnum                 /app/code/_server/../                              
 ------------------ --------------------------------------- -------------------------------------------------------


Database config
===============

 ------------ --------------
  CONNECTION   mysql
 ------------ --------------
  DRIVER       mysql
  HOST         mysql
  PORT         3306
  DATABASE     userfrosting
  USERNAME     docker
  PASSWORD     *********
 ------------ --------------


Testing database connection...
==============================


 [OK] Database connection successful

Chat Discussion (optional)

No response

Description

When attempting to create a user via the admin dashboard without a Group specified, the AJAX request to /api/users results in a 500 error.

Exception thrown:
[ { "type": "Illuminate\\Database\\QueryException", "code": "23000", "message": "SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (userfrosting.users, CONSTRAINT users_group_id_foreign FOREIGN KEY (group_id) REFERENCES groups (id) ON DELETE RESTRICT ON UPDATE RESTRICT) (SQL: insert into users (user_name, group_id, first_name, last_name, email, locale, password, flag_verified, flag_enabled, updated_at, created_at) values (test_user, 0, , , test@userfrosting.com, en_US, $2y$10$f9ngAxbkFhlaSU7HUgre6um/42buCd7uMLY5NUoT1I.7ECl3yuFy6, 1, 1, 2024-10-03 11:25:35, 2024-10-03 11:25:35))", "file": "/app/vendor/illuminate/database/Connection.php", "line": 712 }, { "type": "PDOException", "code": "23000", "message": "SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (userfrosting.users, CONSTRAINT users_group_id_foreign FOREIGN KEY (group_id) REFERENCES groups (id) ON DELETE RESTRICT ON UPDATE RESTRICT)", "file": "/app/vendor/illuminate/database/Connection.php", "line": 501 } ]

Request payload
csrf_name: csrf_value: user_name: test_user group_id: 0 first_name: last_name: email: test@userfrosting.com locale: en_US change_password_mode: manual password: [redacted] passwordc: [redacted]

This is probably happening because it's attempting to set the group_id column as integer zero when creating the user which does not exist as a valid group_id in the groups table. I believe group_id should be excluded from the payload above to effectively leave the group_id value NULL when creating a user that doesn't belong to a group.

If a user must have a group, then the fix would be to remove the "No group" option from the Group dropdown in the "create a new user" modal.

Steps To Reproduce

  1. Log into the userfrosting admin panel
  2. Navigate to Users
  3. Click Create user
  4. Fill out the form in the resulting modal selecting "No group" from the Group dropdown.
  5. Click Create
  6. Ajax request to /api/users results in a 500 error
@lcharette
Copy link
Member

Can you add the debug info (bakery debug)? It might depend on your database.

@interactiveRob
Copy link
Author

@lcharette Sure, just added it above.

@lcharette
Copy link
Member

I can't replicate directly... Does it shows the same error with the root user?

I'll try to dig deeper. In the meantime, I see you're using UF 5.0 ? You might need to upgrade to 5.1 or try a clean install.

@interactiveRob
Copy link
Author

@lcharette yes, this was with the root user. If it helps, I deleted all the default groups Terran, Zerg and Protoss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Not Started
Development

No branches or pull requests

2 participants