How do disable private messages between non staff users?

Hello,

Is it possible to disable private messages between non Admin or moderator users?

Thanks,

Ricardo

1 Like

No need for all this conversation, there is a single Boolean in site settings that does what you want. “Enable private messages”. Seems obvious enough to me…

2 Likes

But this would also disable private messages between a moderator / admin and user?

Nope, it will not. Staff are always immune from these kinds of restrictions.

This is Awesome! Thanks.

I should change the copy for this setting to be more clear…

1 Like

Hmmmm, I’m missing seeing that in the guardian.rb file.

  def can_send_private_message?(target)
    (target.is_a?(Group) || target.is_a?(User)) &&
    # User is authenticated
    authenticated? &&
    # Can't send message to yourself
    is_not_me?(target) &&
    # Have to be a basic level at least
    @user.has_trust_level?(TrustLevel[1]) &&
    # PMs are enabled
    (SiteSetting.enable_private_messages ||
      @user.username == SiteSetting.site_contact_username ||
      @user == Discourse.system_user) &&
    # Can't send PMs to suspended users
    (is_staff? || target.is_a?(Group) || !target.suspended?)
  end
4 Likes

I don’t want to over-step, especially since I don’t know if the changes would have ramifications elsewhere and only did minor testing. .
But as best as I can tell, this seems to work more in tune with the stated intent

  def can_send_private_message?(target)
    (target.is_a?(Group) || target.is_a?(User)) &&
    # User is authenticated
    authenticated? &&
    # Can't send message to yourself
    is_not_me?(target) &&
    # Have to be a basic level at least
-   @user.has_trust_level?(TrustLevel[1]) &&
+   (@user.has_trust_level?(TrustLevel[1]) || is_staff?) &&
    # PMs are enabled
    (SiteSetting.enable_private_messages ||
      @user.username == SiteSetting.site_contact_username ||
-      @user == Discourse.system_user ) &&
+      @user == Discourse.system_user || 
+	  is_staff?) &&
    # Can't send PMs to suspended users
    (is_staff? || target.is_a?(Group) || !target.suspended?)
  end
5 Likes

You were right about the bug here @Mittineague. Should be fixed now:

https://github.com/discourse/discourse/commit/b32f33b3f06602e1d742920b8024949aaaa647b2

7 Likes