Problem/Motivation
The UserSelection entity reference handler currently shows blocked users only for people with the administer users permission. For many user reference fields, only active users are relevant. It would be nice to allow these to be filtered for admins, similar to how the anonymous user can be excluded.
Proposed resolution
Add a configuration option Include blocked to the UserSelection. It defaults to TRUE so existing filters are unchanged.
Remaining tasks
- Write a merge request
- Review
- Commit
User interface changes
A new configuration option Include blocked is available when editing an Entity reference field that targets users.
API changes
None
Data model changes
Configuration for UserSelection supports a new option include_blocked that can be disabled.
| Comment | File | Size | Author |
|---|
Issue fork drupal-2849620
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jhedstromWe'll need to update/add a test for this.
Comment #4
dpiLooking at the patch, it is likely implemented in the reverse. The default behaviour is to exclude blocked, so the option should probably be "Include blocked".
Tackling test failures, and there is a HTML issue with the form field not closing its
<em>tag.Comment #5
dpiInterdiff with #2
Comment #6
dpiComment #7
jhedstromThis would change the current behavior, allowing non-admin users to access blocked users if I'm understanding the logic. In the previous logic from #2, it still forced non-admin users to reference only active users. I'm fine with this either way, but it might be harder to get committed with changing behavior...
Comment #8
jhedstromActually, it wouldn't change any existing fields...it would make fields configurable in such a way that non-admins could reference blocked users, which is also the attempt of #2756179: Separate ability to reference blocked users from 'administer users' permission., so we could perhaps consolidate issues.
Comment #9
jhedstromArg, this is confusing :) The patch in #7 will still always should blocked users for admins, yes? The initial intent was to allow fields to be configured such that even admins cannot reference blocked accounts...
Comment #10
dpiReading your patch, it seemed you wanted to retain the existing behaviour somewhat, because the
>hasPermission('administer users')snippet was still present.If this patch is a binary yes/no you can/t reference blocked users then this would be a behaviour change.
The current behaviour could be retained by having the radio preference:
Comment #11
dpiThis issue is confusing
Comment #12
dpiI see the intent of the original patch was to make it so blocked users would always be excluded, regardless of permission. But then this does not cover situations where you want non-admin to reference blocked.
Comment #13
dpiadmin = user with `administer permissions`
All these multiple binary/negating conditions are confusing, these are the options I see are available.
Option A
Proposed by this issue.
Option B
Option C
Proposed by #6
Comment #15
sukanya.ramakrishnan commentedSubmitting a patch based on option A as proposed by this issue.
Patch did not apply so cudnt get an interdiff
1. Test path has changed, so made changes in the new file. Added one more assertion based on the use cases.
2. Ported patch to 8.5.
Comment #16
jhedstromI think the options where we expose access to blocked users to non-admins is unnecessary, and would be a big change since non-admins cannot see those users anyway (it's the user equivalent of unpublished content), so would still prefer the original option of just making it configurable to remove the blocked users from the autocomplete for admins.
Comment #17
kevin.dutra commentedHmm, I think the included test is giving a false positive (i.e. it's not actually testing what it needs to) because
$handler_settingswas refactored to$configurationat some point and so this patch no longer works the way it's supposed to.Comment #19
kevin.dutra commentedComment #20
kevin.dutra commentedI've made a number of modifications to the last patch:
$referenceable_tests.#statesto the "Include anonymous" field to make it clear that if you exclude blocked users, you won't get the anonymous user either.include_blockedtoTRUE, as that is how it functions prior to this feature and we don't want unexpected behavior to be introduced.include_blockedcheck is now performed before checking for theadminister users permission, which is more expensive.Comment #22
kevin.dutra commentedLooks like some random testbot issue caused those failures, so retry.
Comment #23
idebr commentedThe referenced users are validated in \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::validateReferenceableNewEntities(). This method still validates the user is active based on the permission 'administer users':
This means this patch needs at least two changes:
Comment #25
dalinThis is also related to #2836245: Unable to reference blocked user on node save in that users that don't have the "Administer users" permission are unable to submit the edit form for nodes created by a now blocked user. Editing a node should not require you to alter the history about who created it.
IMO user reference fields should default to allowing all users, unless overridden with the configuration in the attached patch.
Comment #26
dalinComment #27
dalinDisregard #25. It looks like that particular bug is fixed in #2791269: Allow saving pre-existing references to inaccessible items
Comment #38
blanca.esqueda commentedThe patch don't apply to Core 10.3.1
The patch in comment #20 is already included in Core 10: https://api.drupal.org/api/drupal/core%21modules%21user%21src%21Plugin%2...
Comment #39
steven spasbo commentedRerolled patch for 10.3.2
Comment #40
kopeboyThe fix had not been included in core yet!
I applied the rerolled patch in #39, which still applies cleanly even to Drupal 10.3.6, and it worked fine, it just needs some clarification in the field help text imo..
When creating Entity reference fields on Users, this becomes the default:
You would assume from the description that the checked option will make users without the 'administer users' permission able to select blocked users. The opposite is true: the checked option, ie. by default, leaves core behaving like currently (you can't select blocked users unless you have the 'admin users' perm), but if unchecked it hides the blocked users on that field even to roles with the 'aminister users' permission.
So the feature is consistent with the original request, but we can improve the intuitiveness by reverting the label & description:
[ ] Exclude blocked users (unchecked by default - also, leave the "Include the anonymous user." as independent of this option)
Even if this option is not set, only users with the administer users permission may (view and) reference blocked users.
Anyway, I'm not an expert developer so I can't say if technically correct. For example, this contrib module behaviour might be relevant: reference_blocked_users adds a permission to allow referencing blocked users even without the 'administer users' permission, even in the "Authored by" base field. The module worked fine but started producing warning & error after applying patch #20, only after excluding blocked users from the new option (unchecking the current "include" option).
Comment #41
quietone commentedChanges are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.
Comment #42
claudiu.cristeaPlease move this to a MR in order to be properly reviewed
Comment #43
reszlithe current patch has incorrect comparison:
the status = 1 condition needs to be added if the include_blocked is false AND the user has no administer users permission
if the include_blocked is true OR the user has administer users permission, then it should not be added
so I re-rolled it for 10.x
11.x already has an "include_blocked" setting on the selection handler, but it defaults to FALSE
that approach works for entity reference fields, where you can configure it,
but it does not work for the "Name (autocomplete)" views exposed filter
so IMHO the MR for 11.x should only contain a change for the default value to TRUE
but first we need to check why it was introduced with default FALSE
Comment #52
fjgarlin commentedI created https://git.drupalcode.org/project/drupal/-/merge_requests/14549 from the patch in #43.
There were some changes pushed but never made into an MR that are different from the patch https://git.drupalcode.org/issue/drupal-2849620/-/compare/main...2849620...
Setting to needs review to see if the MR is all we need to move forwards with this.
Comment #53
drummAs an admin on Drupal.org, adding people for issue credit offering blocked spam accounts is disorienting.
Comment #54
dcam commentedThere are test failures that must be resolved.
Comment #55
idebr commentedComment #56
solideogloria commentedComment #57
smustgrave commentedSeems like it already got a review from @joachim