FIX: list_suggested_for conditional for personal_message_enabled_groups (#18373)

Follow-up to e62e93f83a,
misplaced a bracket and changed the meaning of the conditional.
This commit is contained in:
Martin Brennan 2022-09-27 16:54:44 +10:00 committed by GitHub
parent ab58b0cffe
commit 7152345ee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -205,7 +205,10 @@ class TopicQuery
# Don't suggest messages unless we have a user, and private messages are
# enabled.
if topic.private_message? && (
@user.blank? || !@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map || !SiteSetting.enable_personal_messages))
@user.blank? ||
!@user.in_any_groups?(SiteSetting.personal_message_enabled_groups_map) ||
!SiteSetting.enable_personal_messages
)
return
end

View File

@ -1157,7 +1157,7 @@ RSpec.describe TopicQuery do
context 'when logged in' do
def suggested_for(topic)
topic_query.list_suggested_for(topic).topics.map { |t| t.id }
topic_query.list_suggested_for(topic)&.topics&.map { |t| t.id }
end
let(:topic) { Fabricate(:topic) }
@ -1260,6 +1260,16 @@ RSpec.describe TopicQuery do
it 'should return the group topics' do
expect(suggested_topics).to match_array([private_group_topic.id, private_message.id])
end
context "when enable_personal_messages is false" do
before do
SiteSetting.enable_personal_messages = false
end
it 'should not return topics by the group user' do
expect(suggested_topics).to eq(nil)
end
end
end
context "with tag filter" do

View File

@ -132,6 +132,11 @@ RSpec.describe TopicViewSerializer do
end
describe 'with private messages' do
before do
SiteSetting.enable_personal_messages = true
Group.refresh_automatic_groups!
end
fab!(:topic) do
Fabricate(:private_message_topic,
highest_post_number: 1,