Problem/Motivation

If you hit the [Add user] button without selecting suggested username under the auto-complete user field, you get a "Invalid user specified." error message.
I found this symptom was reproduced since acl 8.x-1.0-beta2.

Steps to reproduce

1. Copy a username from other web page or txt file, and paste it to the user field.
2. Suggested username appears under the auto-complete user field, but ignore it, and hit the [Add user] button.
3. Get the "Invalid user specified." error message.

Expected behavior

Username, if it is correct, can be entered successfully without selecting suggested username.

Backgroud

When duplicating a node, we need to enter multiple usernames in user field of Access Control tab manually, for example, by copying and pasting from usernames list of the original node.
So it is better each action of selecting suggested username is not necessary.

Proposed resolution

Reverting part of acl.admin.inc of v1.1.0 to v1.0.0-beta1 works OK.
vi acl.admin.inc
----
L.115
elseif (!empty($triggering_element['#value']) && $triggering_element['#value'] == $form['add_button']['#value'] && !empty($form['add']['#value'])) {
$value = $form['add']['#value'];
// if ($match = EntityAutocomplete::extractEntityIdFromAutocompleteInput($value)) {
// $user = @User::load($match);
// }
// if (empty($user)) {
// $form_state->setError($form['add'], t("Invalid user specified."));
// }
// else {
// $user_list[$user->id()] = $user->getDisplayName();
// $form['add']['#value'] = '';
// }
// }
// ->
$match = EntityAutocomplete::extractEntityIdFromAutocompleteInput($value);
if ($match === NULL) {
$user = \Drupal::database()->query("SELECT u.uid, ud.name FROM {users} u INNER JOIN {users_field_data} ud ON u.uid = ud.uid WHERE ud.name = :name", [
'name' => $value,
])->fetchObject();
}
else {
$user = \Drupal::database()->query("SELECT u.uid, ud.name FROM {users} u INNER JOIN {users_field_data} ud ON u.uid = ud.uid WHERE u.uid = :id", [
'id' => $match,
])->fetchObject();
}
if (!$user) {
$form_state->setError($form['add'], t("Invalid user specified."));
}
else {
$user_list[$user->uid] = $user->name;
$form['add']['#value'] = NULL;
}
}
// <-
----

Comments

kubokura created an issue. See original summary.

kubokura’s picture

Issue summary: View changes
kubokura’s picture

Issue summary: View changes
kubokura’s picture

Issue summary: View changes
kubokura’s picture

Title: "Invalid user specified." occurs for auto-complete user field if you don't select suggested item » "Invalid user specified." occurs for auto-complete user field if you don't select suggested username
Issue summary: View changes
kubokura’s picture

Issue summary: View changes
kubokura’s picture

Issue summary: View changes
salvis’s picture

Version: 8.x-1.1 » 8.x-1.x-dev
Status: Active » Postponed (maintainer needs more info)

As you can see above, pasting code as text does not work.

Reverting part of acl.admin.inc of v1.1.0 to v1.0.0-beta1 works OK.

Such version number have never existed.

Please provide a patch against the current -dev version.

kubokura’s picture

StatusFileSize
new1.26 KB

Thank you for reply, and sorry for typo.
wrong: v1.1.0 to v1.0.0-beta1
correct: 8.x-1.1 to 8.x-1.0-beta1

And here is a patch against 8.x-1.x-dev (dev-1.x 963031f).

best regards,

salvis’s picture

Status: Postponed (maintainer needs more info) » Needs review
salvis’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Needs review » Needs work

Never mind the D9.5 — it's the code for 8 and 9. The test bot says

fatal: corrupt patch at line 31

By now we have a 2.x branch for D10, and the patch needs to go against 2.x-dev now. The D8 and D10 branches haven't diverged much yet, the code that you're concerned with is probably still the same.

ad0z’s picture

StatusFileSize
new1.12 KB

I checked the issue and I think we should just let EntityAutocomplete::validateEntityAutocomplete validate this element, instead of trying to validate it ourselves, it will validate and set errors like normal entity_autocomplete form element, it will resolve this issue as well because not static::extractEntityIdFromAutocompleteInput only is called there, but static::matchEntityByTitle as well.
I've tested it as much as I could but I would be good if somebody with live usage of acl_edit_form could test it as well.
I have prepared patch which implement it, so please take a look.

ad0z’s picture

Status: Needs work » Needs review
kubokura’s picture

Hi, thank you for the patch. Unfortunately the patch doesn't work well for me.
Steps to reproduce
1. Copy a username from other web page or txt file, and paste it to the user field.
2. Suggested username appears under the auto-complete user field, but ignore it, and hit the [Add user] button.
3. The username isn't added in "Current users" list without "Invalid user specified." error message.

best regards,

ad0z’s picture

@kubokura are you sure you applying the patch correctly? "Invalid user specified" error message is removed and all errors are handled with EntityAutocomplete::validateEntityAutocomplete and they are different.
What version of the module are you using?

kubokura’s picture

Hi, @ad0z, I'm sorry. I applied the patch against acl 8.x-1.1 on Drupal 9.5.11.
Please disregard my comment of Oct 25.
I still can't upgrade to D10 due to composer error, so I can't apply the patch correctly at this moment.

ad0z’s picture

StatusFileSize
new1.23 KB

@kubokura I've prepared patch for 8.x-1.1, attaching above.

kubokura’s picture

Hi, @ad0z, thank you for the new patch.
The same symptom "The username isn't added in "Current users" list without "Invalid user specified." error message." occurs, so I modified your patch a little, and it works for me.
+ $uid = $form_state->getValue([$acl_wrapper_key, 'add']);
-> + $uid = $form_state->getValue([$acl_wrapper_key, 'view', 'add']);

ad0z’s picture

StatusFileSize
new1.09 KB

@kubokura thanks for finding it, my patch didn't support nested form elements, and I think your patch need update as it hard code element key to be 'view'.
I am attaching patch to 8.x-1.x and 2.x, could you test one for 8.x-1.x?

ad0z’s picture

StatusFileSize
new1.09 KB
kubokura’s picture

Hi, @ad0z, thank you for the update. acl-validate-changes-3389445-19.patch works for me. Username is entered successfully without selecting suggested username.

dillix’s picture

Status: Needs review » Needs work

We need MR for this issue.

nevergone’s picture

  • nevergone committed 06b1c855 on 2.x
    feat: #3389445 "Invalid user specified." occurs for auto-complete user...
nevergone’s picture

Status: Needs work » Fixed
Issue tags: +Needs tests

Committed.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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