On the face of it, these changes allow:
-
Any user who has the min trust level to send a pm, to send a message to any other user who has not disabled pms, regardless of whether or not they are staff.
The issue is this line:
target.staff? || is_staff? || SiteSetting.enable_private_messagesThe first alternative, i.e.
target.staff?, is redundant, as the last alternative will always be true as long as pms are turned on.The
is_staff?check here is used to ensure that staff members can still perform an action even if that action is disabled (this is normal practice in the Discourse code). Keep those two as the only alternatives in that line, i.e.(is_staff? || SiteSetting.enable_private_messages)There was an issue with my initial code, as it didn’t allow staff members to send messages to non-staff members. The way to fix that is by adding the
is_staff?check to that line specifically, i.e.(is_staff? || target.staff) -
Any user of any trust level to send a message to a staff member (e.g. immediately after joining).
The issue is this line:
(target.staff? || @user.has_trust_level?(SiteSetting.min_trust_to_send_messages))This means that if the target is a staff member you don’t need the min trust level. Probably best to require the min trust level for all messages.
-
If a staff member has specifically dis-allowed pms to be sent to them, you will still be able to send pms to them.
The issue is this line:
(target.staff? || is_staff? || target.user_option.allow_private_messages)Unless you want pms to reach staff members even if they have specifically disabled them, remove
target.staff?from this check.