How do disable private messages between non staff users?


(Ricardo Viteri) #1

Hello,

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

Thanks,

Ricardo


(Jeff Atwood) #5

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…


(Ricardo Viteri) #6

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


(Jeff Atwood) #7

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


(Ricardo Viteri) #8

This is Awesome! Thanks.


(Jeff Atwood) #9

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


(Mittineague) #10

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

Allow sending Private Messages to Staff
(Mittineague) #11

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

(Arpit Jalan) #12

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


(Arpit Jalan) #13