FIX: Fix query selecting users not accepting PMs.

This commit is contained in:
Bianca Nenciu 2018-11-28 21:47:45 +02:00 committed by Guo Xiang Tan
parent ffdacba219
commit ddd260941e
2 changed files with 8 additions and 3 deletions

View File

@ -114,7 +114,7 @@ class PostCreator
User
.joins("LEFT JOIN user_options ON user_options.user_id = users.id")
.joins("LEFT JOIN muted_users ON muted_users.muted_user_id = #{@user.id.to_i}")
.joins("LEFT JOIN muted_users ON muted_users.user_id = users.id AND muted_users.muted_user_id = #{@user.id.to_i}")
.where("user_options.user_id IS NOT NULL")
.where("
(user_options.user_id IN (:user_ids) AND NOT user_options.allow_private_messages) OR

View File

@ -1131,6 +1131,7 @@ describe PostCreator do
context "private message to a muted user" do
let(:muted_me) { Fabricate(:evil_trout) }
let(:another_user) { Fabricate(:user) }
it 'should fail' do
updater = UserUpdater.new(muted_me, muted_me)
@ -1141,10 +1142,14 @@ describe PostCreator do
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: "#{muted_me.username}"
target_usernames: "#{muted_me.username},#{another_user.username}"
)
expect(pc).not_to be_valid
expect(pc.errors).to be_present
expect(pc.errors.full_messages).to contain_exactly(
I18n.t(:not_accepting_pms, username: muted_me.username)
)
end
let(:staff_user) { Fabricate(:admin) }