Allow Admin-users set username while user creation

Created on 20 January 2021, almost 4 years ago
Updated 13 October 2023, about 1 year ago

Problem/Motivation

When Admin-user goes to admin/people/create page, he is not able to set username, it's always filled with "email_registration_{generated_string}".
Because Username value is set in the email_registration_form_user_form_alter() hook for all new users without any additional conditions

Proposed resolution

I propose a patch that will check if this is an administrative user-creation form and if Username field is already filled.

Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany Anybody Porta Westfalica

    I agree this would be a helpful, but minor option.

    Still, I think there should be a description letting the (admin) user know about this behavior. And please provide the changes as MR.

  • 🇩🇪Germany Anybody Porta Westfalica

    This also needs to be described in the description of the field, I think!

    So needs work and needs tests. Happy to review a complete MR.

  • 🇩🇪Germany Grevil

    I am not entirely sure, why we even have this logic in place... doesn't make sense to me. We have two different logics for generating the username:

    • The one mentioned in this issue executed through "email_registration_form_user_form_alter()", which will generate the username through 'email_registration_' . \Drupal::service('password_generator')->generate();.
    • The one executed through email_registration_user_insert() run through "email_registration_strip_mail_and_cleanup()" which will generate a unique username from the user mail provided.

    The main problem with "email_registration_form_user_form_alter" is, that it will only get called through "/admin/people/create", but not through "/user/register", meaning a "normal" registration will always lead to the username being generated through "email_registration_user_insert".
    The benefit of the username generation logic in "email_registration_form_user_form_alter" is, that it is easily identifiable, meaning, the module would be a bit more performant. BUT, the username is very cryptic.

    Here is an example of a user with the Mail-address "mail@mail.com":

    • Generated Username through logic 1.: 'email_registration_awnFqFb6af'
    • Generated Username through logic 2.: 'mail' (or mail_1, mail_2, etc. if mail is already taken)

    @Anybody, what do you think about this? In my opinion, we should settle on one generation logic, where logic 1 is generally better performing but more cryptic.

  • 🇩🇪Germany Anybody Porta Westfalica

    @Grevil: I agree it doesn't make sense to have two logics in place here and I agree the admin should always be able to override / set the username with priority.

    So from my perspective we need a 2.x meta issue to rework these points, combining issues like

    and possible others combined for a clear and safe functionality.

    @Grevil could you prepare such a meta issue?
    I think the listed issues (and this one) should be subtasks then.

  • 🇩🇪Germany Grevil

    Ok, let's settle on one username scheme and set that value as the "default value" on "admin/people/create" IF the value is empty. 👍

  • 🇩🇪Germany Grevil

    OK, my bad,
    'email_registration_' . \Drupal::service('password_generator')->generate(); is just used temporarily and overwritten through the insert hook. I just read the first if case in the insert hook wrong.

    So we do not need to settle on anything. We can simply use the existing logic.

    Back to the original issue:

    When Admin-user goes to admin/people/create page, he is not able to set username, it's always filled with "email_registration_{generated_string}"

    I agree, we should never prefill the username anyway. The admin should decide what the username should be and if he leaves the username empty, we use the generation logic from the module.

  • Status changed to Active about 1 year ago
  • Status changed to Closed: won't fix about 1 year ago
  • 🇩🇪Germany Grevil

    This won't be fixed. "email_registration_{generated_string}" is only set as the default value and can be changed at will. Unfortunately it is not (easily) possible, to make the username field not required, as core will still throw an error.

    So we will simply adjust the description for an admin user, so he knows if he leaves the default value ("email_registration_{generated_string}"), this username is simply just temporary and will be overwritten, through the module's presave hook.

  • 🇩🇪Germany Anybody Porta Westfalica

    @Grevil: I'd suggest creating a follow-up feature request then with the planned (leave empty vs. fill) functionality. I guess it is possible, but not easy and perhaps not worth it. Having this documented below the field (and setting the field disabled?) should be an appropriate improvement for now!

  • 🇩🇪Germany Grevil

    Having this documented below the field (and setting the field disabled?) should be an appropriate improvement for now!

    Almost, we should only disable the field on specific permissions. Admin user shouldn't have the field disabled, also not a user who has the "change own username" permission, who is on his edit user page.

    I don't think a follow-up issue would be worth it.

  • Status changed to Fixed about 1 year ago
  • 🇩🇪Germany Grevil

    Alright, we found a nice workaround for this in 🌱 [2.x] Rework username generation save logic Active ! "email_registration_{generated_string}" won't be seen by any user any more, instead it will be temporarily set through the validation. We can't leave it entirely due to core validations.

    FIXED!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024