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 because validateReferenceableEntities() (plain UserSelection) only checks that the entity exists and is referenceable — not the enable flag.
  • Role expansion: the privatemsg send to role feature 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 an enable check.

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 when user.data reports enable for them.
  • Direct input validation: when looping over the validated entity IDs, reject
    the recipient with a form error if enable is 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

Command icon 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

lisa.rae created an issue. See original summary.

lisa.rae’s picture

Status: Active » Needs review

ivnish changed the visibility of the branch 3617053-recipients-who-disabled to hidden.

  • ivnish committed 5a264af5 on 2.0.x authored by lisa.rae
    fix: #3617053 Recipients who disabled private messages can still be...
ivnish’s picture

Status: Needs review » Fixed

Nice catch! Thanks!

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.