Problem/Motivation
Users can opt out of private messages by unchecking "Enable private messages"
on their profile (stored via user.data under privatemsg/enable). The autocomplete matches already filter out such users (PrivatemsgAutocompleteMatcher checks enable), but the form validator (PrivatemsgAutocomplete::validateEntityIdAutocomplete) never checks the flag:
- Direct input: a sender can type
Username (123)manually, bypassing the autocomplete, and the validator accepts the user becausevalidateReferenceableEntities()(plainUserSelection) only checks that the entity exists and is referenceable — not theenableflag. - Role expansion: the
privatemsg send to rolefeature expands a role to all users of the role, including users who disabled private messages. The validator's role-expansion branch adds every role user as a recipient without anenablecheck.
Result: users who disabled private messages still receive messages and email
notifications, defeating their documented opt-out.
Steps to reproduce
1. User B unchecks "Enable private messages" on their profile.
2. Log in as user A with privatemsg write messages (+ privatemsg send to role for the role path).
3. On /messages/new, type UserB (123) directly (or, if B belongs to a role and the role is in allowed_roles, type RoleName (role)).
4. Submit — the message is delivered to B despite the disabled setting, and B receives the email notification.
Proposed resolution
Enforce the enable setting in the validator, on both paths:
- Role expansion (
src/Element/PrivatemsgAutocomplete.php): only add a role
user to the recipient list whenuser.datareportsenablefor them. - Direct input validation: when looping over the validated entity IDs, reject
the recipient with a form error ifenableis not set (mirroring the existing
blocked-user check), so a message cannot be created for a disabled user.
The privatemsg_send-relevant checks stay in the validator (the same place the
blocked-user check already lives), so all paths into message creation — direct
typing and role expansion — honor the opt-out.
Remaining tasks
Patch is forthcoming.
Issue fork privatemsg-3617053
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:
- Issue-3617053
changes, plain diff MR !63
- 3617053-recipients-who-disabled
compare
Comments
Comment #3
lisa.rae commentedComment #6
ivnishNice catch! Thanks!