From e8756e1a955abdb48978492a2c1a0fd8e740febc Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 17 Jun 2020 14:26:14 -0400 Subject: [PATCH] FIX: Muted/Ignore should prevent PMs regardless of case sensitivity --- lib/post_creator.rb | 4 ++-- spec/components/post_creator_spec.rb | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/post_creator.rb b/lib/post_creator.rb index c3b9556df21..6a9e4ca8735 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -96,7 +96,7 @@ class PostCreator end if @opts[:target_usernames].present? && !skip_validations? && !@user.staff? - names = @opts[:target_usernames].split(',') + names = @opts[:target_usernames].split(',').flatten.map(&:downcase) # Make sure max_allowed_message_recipients setting is respected max_allowed_message_recipients = SiteSetting.max_allowed_message_recipients @@ -111,7 +111,7 @@ class PostCreator end # Make sure none of the users have muted the creator - users = User.where(username: names).pluck(:id, :username).to_h + users = User.where(username_lower: names).pluck(:id, :username).to_h User .joins("LEFT JOIN user_options ON user_options.user_id = users.id") diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 59369598049..27fba7c4861 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -1203,7 +1203,7 @@ describe PostCreator do end context 'private message to a user that has disabled private messages' do - fab!(:another_user) { Fabricate(:user) } + fab!(:another_user) { Fabricate(:user, username: 'HelloWorld') } before do another_user.user_option.update!(allow_private_messages: false) @@ -1224,6 +1224,18 @@ describe PostCreator do "not_accepting_pms", username: another_user.username )) end + + it 'should not be valid if the name is downcased' do + post_creator = PostCreator.new( + user, + title: 'this message is to someone who muted me!', + raw: "you will have to see this even if you muted me!", + archetype: Archetype.private_message, + target_usernames: "#{another_user.username.downcase}" + ) + + expect(post_creator).to_not be_valid + end end context "private message to a muted user" do